FRAMEWORK GUIDES · 6 MIN READ

Pytest Flaky Tests: Isolating Fixtures, Async Loops, and Reruns

Track and fix Pytest flaky tests with pytest-rerunfailures, JUnit XML or pytest-json-report, fixture isolation, and FlakeCheck analytics.

Tracking Pytest Reruns in CI

Python suites frequently suffer from module-scoped fixture bleed, shared SQLite/Postgres state, and unclosed asyncio event loops. Pair pytest-rerunfailures with JUnit XML or pytest-json-report so FlakeCheck captures every retry attempt.

pytest --reruns 2 --junitxml=pytest-junit.xml
npx @onurdrsn/flakecheck ingest pytest-junit.xml --format junit

Detecting Order-Dependent Pytest Suites

Install pytest-randomly in CI to shuffle execution order on every run. When a test fails only in specific orderings, FlakeCheck flags its flip rate and surfaces order_dependency remediation guidance.

Eliminate flaky tests automatically with FlakeCheck

Stream your JUnit, CTRF, Jest, Vitest, Playwright, Pytest, Mocha, or Go reports to FlakeCheck and get statistical scoring + auto-quarantine in minutes.

Related Guides