Test misplaced or incorrect Scenario keywords.
(pytester)
| 106 | |
| 107 | |
| 108 | def 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 | |
| 156 | def test_misplaced_rule_error(pytester): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…