Skip to content

Commit c232828

Browse files
committed
No need to keep a counter, just try to pop from the stack if any
1 parent 825fcf8 commit c232828

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/pytest_bdd/plugin.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
from .parser import Feature, Scenario, Step
2222

2323

24-
# Counter to track how many times pytest initialization was started
25-
_INIT_COUNT = 0
26-
27-
2824
def pytest_addhooks(pluginmanager: PytestPluginManager) -> None:
2925
"""Register plugin hooks."""
3026
from pytest_bdd import hooks
@@ -56,8 +52,6 @@ def _pytest_bdd_example() -> dict:
5652

5753
def pytest_addoption(parser: Parser) -> None:
5854
"""Add pytest-bdd options."""
59-
global _INIT_COUNT
60-
_INIT_COUNT += 1
6155
add_bdd_ini(parser)
6256
cucumber_json.add_options(parser)
6357
generation.add_options(parser)
@@ -72,19 +66,15 @@ def add_bdd_ini(parser: Parser) -> None:
7266
def pytest_configure(config: Config) -> None:
7367
"""Configure all subplugins."""
7468
CONFIG_STACK.append(config)
75-
assert _INIT_COUNT == len(CONFIG_STACK)
7669
cucumber_json.configure(config)
7770
gherkin_terminal_reporter.configure(config)
7871

7972

8073
def pytest_unconfigure(config: Config) -> None:
8174
"""Unconfigure all subplugins."""
82-
global _INIT_COUNT
83-
assert len(CONFIG_STACK) <= _INIT_COUNT
84-
if len(CONFIG_STACK) == _INIT_COUNT:
75+
if CONFIG_STACK:
8576
CONFIG_STACK.pop()
86-
cucumber_json.unconfigure(config)
87-
_INIT_COUNT -= 1
77+
cucumber_json.unconfigure(config)
8878

8979

9080
@pytest.hookimpl(hookwrapper=True)

0 commit comments

Comments
 (0)