QA-PY-004 — Bare truthiness assert on complex object
Generated from the rule registry. Get the same detail from the CLI with
mjolnir explain QA-PY-004.
| Field | Value |
|---|---|
| Severity | warning |
| Confidence | medium |
| Tier | quarantine |
| Measured FP rate | not yet measured |
| Evidence level | E1 |
| QA impact | False-green risk (FALSE-GREEN) |
| 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
This passes for any truthy value — a wrong object, wrong count, or partially-built result all slip through. It verifies existence, not correctness.
What gets flagged (real detector output)
Bare truthiness assert: `assert order`.Example from this rule's own must-fire fixture: tests/fixtures/QA-PY-004/must-fire/attribute-chains.py
The fix
Assert the specific expected value or property: assert result.id == expected, assert len(items) == 3.
Confirmed NOT to fire on the corresponding clean pattern
Verified against tests/fixtures/QA-PY-004/must-not-fire/constant-asserts.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 | 534 |
| getsentry-sentry | 889 |
| negative-fixtures | 1 |
| pallets-click | 4 |
| positive-fixtures | 11 |
| psf-requests | 11 |
| pyca-cryptography | 17 |
| pytest-dev-pytest | 84 |
| reflex-dev-reflex | 140 |
| streamlit-streamlit | 361 |