MCPcopy Create free account
hub / github.com/pytest-dev/pytest-bdd / test_misplaced_scenario_error

Function test_misplaced_scenario_error

tests/parser/test_errors.py:108–153  ·  view source on GitHub ↗

Test misplaced or incorrect Scenario keywords.

(pytester)

Source from the content-addressed store, hash-verified

106
107
108def test_misplaced_scenario_error(pytester):
109 """Test misplaced or incorrect Scenario keywords."""
110 features = pytester.mkdir("features")
111 features.joinpath("test.feature").write_text(
112 textwrap.dedent(
113 """
114 Scenario: First scenario
115 Given a step
116
117 Scenario: Misplaced scenario
118 Given another step
119 When I have something wrong
120 """
121 ),
122 encoding="utf-8",
123 )
124 pytester.makepyfile(
125 textwrap.dedent(
126 """
127 from pytest_bdd import scenarios, given, when
128
129 @given("a step")
130 def a_step():
131 pass
132
133 @given("another step")
134 def another_step():
135 pass
136
137 @when("I have something wrong")
138 def something_wrong():
139 pass
140
141 scenarios('features')
142 """
143 )
144 )
145
146 result = pytester.runpytest()
147
148 # Expect that no ScenarioError will actually be raised here
149 result.stdout.fnmatch_lines(
150 [
151 "*ScenarioError: Misplaced or incorrect 'Scenario' keyword. Ensure it's correctly placed. There might be a missing Feature section.*"
152 ]
153 )
154
155
156def test_misplaced_rule_error(pytester):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…