No need to keep a counter, just try to pop from the stack if any
This commit is contained in:
parent
825fcf804b
commit
c23282819b
|
@ -21,10 +21,6 @@ if TYPE_CHECKING:
|
||||||
from .parser import Feature, Scenario, Step
|
from .parser import Feature, Scenario, Step
|
||||||
|
|
||||||
|
|
||||||
# Counter to track how many times pytest initialization was started
|
|
||||||
_INIT_COUNT = 0
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_addhooks(pluginmanager: PytestPluginManager) -> None:
|
def pytest_addhooks(pluginmanager: PytestPluginManager) -> None:
|
||||||
"""Register plugin hooks."""
|
"""Register plugin hooks."""
|
||||||
from pytest_bdd import hooks
|
from pytest_bdd import hooks
|
||||||
|
@ -56,8 +52,6 @@ def _pytest_bdd_example() -> dict:
|
||||||
|
|
||||||
def pytest_addoption(parser: Parser) -> None:
|
def pytest_addoption(parser: Parser) -> None:
|
||||||
"""Add pytest-bdd options."""
|
"""Add pytest-bdd options."""
|
||||||
global _INIT_COUNT
|
|
||||||
_INIT_COUNT += 1
|
|
||||||
add_bdd_ini(parser)
|
add_bdd_ini(parser)
|
||||||
cucumber_json.add_options(parser)
|
cucumber_json.add_options(parser)
|
||||||
generation.add_options(parser)
|
generation.add_options(parser)
|
||||||
|
@ -72,19 +66,15 @@ def add_bdd_ini(parser: Parser) -> None:
|
||||||
def pytest_configure(config: Config) -> None:
|
def pytest_configure(config: Config) -> None:
|
||||||
"""Configure all subplugins."""
|
"""Configure all subplugins."""
|
||||||
CONFIG_STACK.append(config)
|
CONFIG_STACK.append(config)
|
||||||
assert _INIT_COUNT == len(CONFIG_STACK)
|
|
||||||
cucumber_json.configure(config)
|
cucumber_json.configure(config)
|
||||||
gherkin_terminal_reporter.configure(config)
|
gherkin_terminal_reporter.configure(config)
|
||||||
|
|
||||||
|
|
||||||
def pytest_unconfigure(config: Config) -> None:
|
def pytest_unconfigure(config: Config) -> None:
|
||||||
"""Unconfigure all subplugins."""
|
"""Unconfigure all subplugins."""
|
||||||
global _INIT_COUNT
|
if CONFIG_STACK:
|
||||||
assert len(CONFIG_STACK) <= _INIT_COUNT
|
|
||||||
if len(CONFIG_STACK) == _INIT_COUNT:
|
|
||||||
CONFIG_STACK.pop()
|
CONFIG_STACK.pop()
|
||||||
cucumber_json.unconfigure(config)
|
cucumber_json.unconfigure(config)
|
||||||
_INIT_COUNT -= 1
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(hookwrapper=True)
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
|
|
Loading…
Reference in New Issue