diff --git a/src/pytest_bdd/plugin.py b/src/pytest_bdd/plugin.py index 486cdf8..08ceaa0 100644 --- a/src/pytest_bdd/plugin.py +++ b/src/pytest_bdd/plugin.py @@ -72,7 +72,8 @@ def pytest_configure(config: Config) -> None: def pytest_unconfigure(config: Config) -> None: """Unconfigure all subplugins.""" - CONFIG_STACK.pop() + if CONFIG_STACK: + CONFIG_STACK.pop() cucumber_json.unconfigure(config) diff --git a/tests/test_hooks.py b/tests/test_hooks.py index e3fda90..53b44f7 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -135,3 +135,21 @@ def test_pytest_bdd_after_scenario_called_after_scenario(pytester): assert scenario_1.name == "Scenario 1" assert scenario_2.name == "Scenario 2" + + +def test_pytest_unconfigure_without_configure(pytester): + """ + Simulate a plugin forcing an exit during configuration before bdd is configured + https://github.com/pytest-dev/pytest-bdd/issues/362 + """ + pytester.makeconftest( + """ + import pytest + + def pytest_configure(config): + pytest.exit("Exit during configure", 0) + """ + ) + + result = pytester.runpytest() + assert result.ret == 0