Skip to main content
Community
Q&A

How do you prevent pytest fixture scope mismatches from causing silent test pollution?

Ajitesh Mohanta
Ajitesh MohantaAmbassador
May 13, 2026 691 0
We had a bug where a `function`-scoped test was accidentally using a `session`-scoped fixture that mutated shared state. Tests passed individually, failed in certain orders in CI. The failure was silent — no error about scope mismatch, just wrong data. Is there a pytest plugin or configuration that: - Warns when a broader-scoped fixture is modified by a narrower-scoped test? - Helps detect test order dependencies? I know about `pytest-randomly` for randomising order to surface these, but I want something that catches the root cause.

No replies yet. Be the first to answer this question!

Join the discussion

Sign in to join the discussion

Sign in
How do you prevent pytest fixture scope mismatches from causing silent test pollution? — Community | QABash