Skip to content

QA-PY-005 — time.sleep() in test ​

← Back to the rule catalog

Generated from the rule registry. Get the same detail from the CLI with mjolnir explain QA-PY-005.

FieldValue
Severitywarning
Confidencehigh
Tierextended
Measured FP rate13% (n=23)
Evidence levelE2
QA impactFlaky-test risk (FLAKY-RISK)
False-positive risk (author estimate)low
Autofix availableno
Languagespython
Frameworkspytest
Detection strategyLEXICAL
Introduced inv0.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):

RepoOccurrences
apache-airflow49
getsentry-sentry39
negative-fixtures1
positive-fixtures13
psf-requests3
reflex-dev-reflex16
streamlit-streamlit29

Released under the MIT License.