Skip to content

Commit b901519

Browse files
authored
Merge pull request #641 from n3world/issue_362_unconfigure
Issue #362: Only unconfigure if configured
2 parents 5707669 + c232828 commit b901519

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/pytest_bdd/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def pytest_configure(config: Config) -> None:
7272

7373
def pytest_unconfigure(config: Config) -> None:
7474
"""Unconfigure all subplugins."""
75-
CONFIG_STACK.pop()
75+
if CONFIG_STACK:
76+
CONFIG_STACK.pop()
7677
cucumber_json.unconfigure(config)
7778

7879

tests/test_hooks.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,21 @@ def pytest_bdd_after_scenario(request, feature, scenario):
135135

136136
assert scenario_1.name == "Scenario 1"
137137
assert scenario_2.name == "Scenario 2"
138+
139+
140+
def test_pytest_unconfigure_without_configure(pytester):
141+
"""
142+
Simulate a plugin forcing an exit during configuration before bdd is configured
143+
https://github.com/pytest-dev/pytest-bdd/issues/362
144+
"""
145+
pytester.makeconftest(
146+
"""
147+
import pytest
148+
149+
def pytest_configure(config):
150+
pytest.exit("Exit during configure", 0)
151+
"""
152+
)
153+
154+
result = pytester.runpytest()
155+
assert result.ret == 0

0 commit comments

Comments
 (0)