QA-PY-011 — Mutable fixture shared across tests
Generated from the rule registry. Get the same detail from the CLI with
mjolnir explain QA-PY-011.
| Field | Value |
|---|---|
| Severity | warning |
| Confidence | medium |
| Tier | extended |
| Measured FP rate | 10% (n=10) |
| Evidence level | E1 |
| QA impact | Flaky-test risk (FLAKY-RISK) |
| False-positive risk (author estimate) | medium |
| Autofix available | no |
| Languages | python |
| Frameworks | pytest |
| Detection strategy | LEXICAL |
| Introduced in | v0.3.0 |
Why this fails in production
Tests that mutate a shared module/session fixture create hidden execution-order dependency — the suite passes in one order and fails in another.
What gets flagged (real detector output)
Fixture `shared_cart` is session-scoped and returns a mutable collection.Example from this rule's own must-fire fixture: tests/fixtures/QA-PY-011/must-fire/mutable-fixture.py
The fix
Use function scope (default), or return an immutable copy / factory so each test gets fresh state.
Confirmed NOT to fire on the corresponding clean pattern
Verified against tests/fixtures/QA-PY-011/must-not-fire/clean.py — a legitimate, similar-looking pattern this rule correctly leaves alone.
Corpus-measured false-positive risk
Real occurrence counts from npm run corpus:audit against actively-maintained OSS repos — reproduce yourself, don't just trust this table (see the false-positive audit):
| Repo | Occurrences |
|---|---|
| apache-airflow | 4 |
| positive-fixtures | 5 |
| pytest-dev-pytest | 1 |