|
1 | 1 | import textwrap
|
2 | 2 |
|
| 3 | +from pytest_bdd.utils import collect_dumped_objects |
3 | 4 |
|
4 |
| -def test_hooks(pytester): |
| 5 | + |
| 6 | +def test_conftest_module_evaluated_twice(pytester): |
| 7 | + """Regression test for https://github.com/pytest-dev/pytest-bdd/issues/62""" |
5 | 8 | pytester.makeconftest("")
|
6 | 9 |
|
7 | 10 | subdir = pytester.mkpydir("subdir")
|
@@ -74,3 +77,61 @@ def test_convert_me_to_custom_item_and_assert_true():
|
74 | 77 |
|
75 | 78 | result = pytester.runpytest()
|
76 | 79 | result.assert_outcomes(passed=1)
|
| 80 | + |
| 81 | + |
| 82 | +def test_pytest_bdd_after_scenario_called_after_scenario(pytester): |
| 83 | + """Regression test for https://github.com/pytest-dev/pytest-bdd/pull/577""" |
| 84 | + |
| 85 | + pytester.makefile( |
| 86 | + ".feature", |
| 87 | + foo=textwrap.dedent( |
| 88 | + """\ |
| 89 | + Feature: A feature |
| 90 | + Scenario: Scenario 1 |
| 91 | + Given foo |
| 92 | + When bar |
| 93 | + Then baz |
| 94 | +
|
| 95 | + Scenario: Scenario 2 |
| 96 | + When bar |
| 97 | + Then baz |
| 98 | + """ |
| 99 | + ), |
| 100 | + ) |
| 101 | + |
| 102 | + pytester.makepyfile( |
| 103 | + """ |
| 104 | + import pytest |
| 105 | + from pytest_bdd import given, when, then, scenarios |
| 106 | +
|
| 107 | +
|
| 108 | + scenarios("foo.feature") |
| 109 | +
|
| 110 | +
|
| 111 | + @given("foo") |
| 112 | + @when("bar") |
| 113 | + @then("baz") |
| 114 | + def _(): |
| 115 | + pass |
| 116 | + """ |
| 117 | + ) |
| 118 | + |
| 119 | + pytester.makeconftest( |
| 120 | + """ |
| 121 | + from pytest_bdd.utils import dump_obj |
| 122 | +
|
| 123 | + def pytest_bdd_after_scenario(request, feature, scenario): |
| 124 | + dump_obj([feature, scenario]) |
| 125 | + """ |
| 126 | + ) |
| 127 | + |
| 128 | + result = pytester.runpytest("-s") |
| 129 | + result.assert_outcomes(passed=2) |
| 130 | + |
| 131 | + hook_calls = collect_dumped_objects(result) |
| 132 | + assert len(hook_calls) == 2 |
| 133 | + [(feature, scenario_1), (feature_2, scenario_2)] = hook_calls |
| 134 | + assert feature.name == feature_2.name == "A feature" |
| 135 | + |
| 136 | + assert scenario_1.name == "Scenario 1" |
| 137 | + assert scenario_2.name == "Scenario 2" |
0 commit comments