Skip to content

Commit f85e551

Browse files
Use patch.object context manager instead of monkeypatch in warn test
1 parent b837fc9 commit f85e551

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

tests/parser/test_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import textwrap
44
from pathlib import Path
5+
from unittest.mock import patch
56

67
import pytest
78

@@ -857,7 +858,7 @@ def test_parser():
857858
assert gherkin_doc == expected_document
858859

859860

860-
def test_feature_parser_warns_on_unknown_child_kinds(tmp_path, monkeypatch):
861+
def test_feature_parser_warns_on_unknown_child_kinds(tmp_path):
861862
"""A Child with none of background/rule/scenario set is skipped with a warning.
862863
863864
The gherkin AST reserves the right to grow new child kinds; ``Child.from_dict``
@@ -882,10 +883,9 @@ def get_gherkin_document_with_unknown_child(abs_filename: str, encoding: str = "
882883
document.feature.children.append(Child())
883884
return document
884885

885-
monkeypatch.setattr(parser_module, "get_gherkin_document", get_gherkin_document_with_unknown_child)
886-
887-
with pytest.warns(UserWarning, match="Unknown gherkin child"):
888-
feature = parser_module.FeatureParser(str(tmp_path), "minimal.feature").parse()
886+
with patch.object(parser_module, "get_gherkin_document", get_gherkin_document_with_unknown_child):
887+
with pytest.warns(UserWarning, match="Unknown gherkin child"):
888+
feature = parser_module.FeatureParser(str(tmp_path), "minimal.feature").parse()
889889

890890
assert list(feature.scenarios) == ["A scenario"]
891891
assert feature.background is None

0 commit comments

Comments
 (0)