QA-PY-005 — time.sleep() in test
Generated from the rule registry. Get the same detail from the CLI with
mjolnir explain QA-PY-005.
| Field | Value |
|---|---|
| Severity | warning |
| Confidence | high |
| Tier | extended |
| Measured FP rate | 13% (n=23) |
| Evidence level | E2 |
| QA impact | Flaky-test risk (FLAKY-RISK) |
| False-positive risk (author estimate) | low |
| Autofix available | no |
| Languages | python |
| Frameworks | pytest |
| Detection strategy | LEXICAL |
| Introduced in | v0.3.0 |
Why this fails in production
Fixed sleeps make tests slow and flaky — they guess at timing instead of waiting for state.
What gets flagged (real detector output)
Hard sleep: `time.sleep(5…`.Example from this rule's own must-fire fixture: tests/fixtures/QA-PY-005/must-fire/sleepy.py
The fix
Wait for an explicit condition (polling helper, pytest-timeout wait_until, or event).
Confirmed NOT to fire on the corresponding clean pattern
Verified against tests/fixtures/QA-PY-005/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 | 49 |
| getsentry-sentry | 39 |
| negative-fixtures | 1 |
| positive-fixtures | 13 |
| psf-requests | 3 |
| reflex-dev-reflex | 16 |
| streamlit-streamlit | 29 |