pytest Fixtures and Plugin Interoperability: Managing Session-Scoped State
0 reputation · 13 Aug 2020, 20:21 UTC
When integrating custom pytest plugins with session-scoped fixtures, there is a potential for state leakage across disparate test modules. While pytest ensures that session-scoped fixtures persist for the duration of the test run, the interaction between plugin-defined fixtures and local conftest.py definitions can create implicit dependencies.
The primary goal is to ensure that session-level state managed by a plugin remains isolated or predictably reset when multiple plugins attempt to modify the same global resource. This becomes complex when parameterized fixtures are used to inject different configurations into a shared session resource.
- How does pytest resolve naming conflicts when a plugin and a local
conftest.pyboth define a session-scoped fixture with the same name? - What is the deterministic behavior for the teardown order when a session-scoped plugin fixture depends on a session-scoped local fixture?