Skip to main content

flakehound

PyPI Python CI CodeQL License: MIT

Find flaky tests and prove why they're flaky.

Flaky tests pass sometimes and fail sometimes with no code change. Most tools just retry them, which hides the problem. flakehound runs your pytest suite under deliberately hostile conditions, finds the tests that flip, and tells you the cause, with evidence from real runs and a command that reproduces it. It also finds problems that haven't bitten you yet.

flakehound output on the demo project

  • 🆓 Free forever. No accounts, no servers, no paid services.
  • 🔒 Local and private. Offline, no telemetry, secrets redacted from every report.
  • 🧪 Evidence, not guesses. Every verdict comes from runs that prove it, and every repro command is run for real before it's marked verified.

What it finds

Problem Example What flakehound tells you
Order dependency a test leaves an item in a shared cart the polluter test and the leaked state: shop.cart: [] → ['apple']
Needs another test a test only passes after a setup-like test ran the test it secretly depends on
Randomness assert random.random() < 0.8 the failing seed, and a repro that replays it
Set/dict ordering comparing ",".join(a_set) to a string that PYTHONHASHSEED is the cause
Time bombs breaks on the last day of the month, on Feb 29, in another timezone the exact date/timezone, before it happens
Sleep used as a wait sleep(0.06) then assert a thread finished the exact sleep() line that will fail on a slow CI machine
Race conditions unlocked read-modify-write from threads that it fails when threads interleave

Quickstart

pip install flakehound
cd your-project
flakehound run

That's it: no config. Try it on the included demo project to see every kind of problem. The same results as a Markdown report: docs/example-report.md.

⚠️ flakehound runs your test suite (many times). Only run it on code you trust.

Options

Option Meaning
-n, --runs N How many times to run the suite (default 10)
-j, --workers N Parallel runs (default: CPU cores − 1, max 8)
--seed N Replay an earlier session exactly
--json PATH Also write a machine-readable report
--markdown PATH Also write a Markdown report (for PR comments)
--fail-on KINDS What makes exit code 1: flaky, time-bomb, racy, broken, suspected, none (default flaky,time-bomb,racy)
--no-diagnose Only detect flaky tests, don't explain them
--max-diagnose N Diagnose at most N flaky tests (default 20)
--no-probes Skip all probe runs (timezones, risky dates, timing)
--no-timing Skip only the timing probes
--no-step-summary Don't add the report to the GitHub Actions job summary
--timeout S Kill a single run after S seconds (default 600)
-- ARGS Anything after -- goes straight to pytest

Exit codes: 0 no problems, 1 problems found (by default only flaky tests and confirmed time bombs or racy tests fail a build), 2 usage or collection error.

In CI

Hunting runs your suite many times, so run it on a schedule rather than on every push:

# .github/workflows/flakehound.yml
on:
  schedule: [{ cron: "0 3 * * *" }]   # nightly
  workflow_dispatch:
permissions:
  contents: read
jobs:
  hunt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with: { persist-credentials: false }
      - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
        with: { python-version: "3.12" }
      - run: pip install -e . flakehound
      - run: flakehound run --json flakehound.json

In GitHub Actions the Markdown report appears on the run's summary page automatically.

Quarantine

Found a flaky test you can't fix today? Quarantine it so it stops failing the build, without hiding it:

flakehound quarantine add tests/test_cart.py::test_cart_starts_empty --reason "polluted by test_add_item"
flakehound quarantine add --from-report flakehound.json    # everything flakehound found
flakehound quarantine list
flakehound quarantine remove tests/test_cart.py::test_cart_starts_empty
  • The list is one file, .flakehound/quarantine.toml: commit it, review it, revert it. flakehound never edits your test files.
  • Every change shows a diff and asks first (--yes skips the prompt).
  • pytest still runs quarantined tests as non-strict xfail (or skip), so you see XPASS once one is fixed. Disable for one run with pytest -p no:flakehound-quarantine. The plugin does nothing when the file doesn't exist.
  • flakehound run ignores the quarantine, so quarantined tests keep being hunted.

How it works

flakehound changes one factor at a time, like a science experiment:

  1. Shake. Run the whole suite many times in parallel, each with a different test order, random seed and PYTHONHASHSEED, all recorded. Tests that both pass and fail are flaky; tests that always fail are rechecked, then reported as broken.
  2. Isolate. Run each flaky test alone with the exact seeds of the runs where it failed. Only the order changed, so if it now passes, order is proven to be the cause.
  3. Find the culprit. Try the tests whose position best correlates with the failure, then shrink the preceding tests with delta debugging, in parallel batches.
  4. Name the leaked state. Snapshot global state before and after the culprit: module variables, object and class attributes, environment variables (secret values are never shown), working directory, sys.path, project files and logging config.
  5. Seeds. For flaky tests that aren't about order, swap one seed at a time between a failing and a passing run: the one that flips the result is the cause. If identical seeds still give different results, the test is nondeterministic.
  6. Time bomb probes. Runs with the baseline's exact order and seeds, but in UTC+14, UTC−12, just before midnight, on the last day of the month, on New Year's Eve and on Feb 29. The clock is shifted, not frozen, so code that waits on time still works.
  7. Timing probes. One run where every sleep() on the test's main thread is 20× shorter (background work keeps its real speed, like a slow machine), and one where threads switch far more often. Then one sleep() call site at a time, to find the line.
  8. Confirm and verify. Findings are re-run, and each printed repro command is run for real; it's marked verified only if it fails exactly as printed.

Repro commands that replay a seed, clock or timing stress use flakehound's pytest plugin (-p flakehound.adapters.pytest.plugin), so they need flakehound installed. That plugin never loads into your normal pytest runs on its own.

How it compares

Tool Retries Detects Explains why Free & local
pytest-rerunfailures, flaky ✅ ❌ ❌ ✅
pytest-randomly ❌ order/seed issues show up ❌ ✅
detect-test-pollution ❌ ❌ the polluter test (you drive it) ✅
Trunk, BuildPulse, Datadog ✅ from CI history little ❌ paid / uploads data
flakehound ❌ (on purpose) ✅ + time bombs + racy tests polluter, leaked state, seed, date, timezone, sleep() line, race ✅

Limitations

  • Python + pytest only, for now.
  • asyncio.sleep is not shortened by the timing probes.
  • State hidden in fixtures, databases or external services can't be seen by the leak detector; the report says so instead of guessing.
  • Thread stress exposes races that happen around Python function calls.
  • Hunting takes many runs of your suite: use -n, -j and --max-diagnose on large suites.

Roadmap

  • GitHub Actions history mode: find flaky tests from past CI runs without running anything
  • A ready-made GitHub Action
  • Adapters for Jest/Vitest, Go test and JUnit
  • Optional AI explanations (local models via Ollama, or your own key; never required)

See CHANGELOG.md for what's in each release.

Contributing and security

Contributions are welcome: see CONTRIBUTING.md. To report a vulnerability privately, see SECURITY.md.

License

MIT

Metadata

Release files for flakehound 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flakehound 0.1.0
File Size Uploaded Provenance Actions
flakehound-0.1.0.tar.gz 70.6 kB With provenance Details for flakehound-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flakehound 0.1.0
File Interpreter ABI Platform Actions
flakehound-0.1.0-py3-none-any.whl Python 3 none any Details for flakehound-0.1.0-py3-none-any.whl

Total release size: 141.4 kB

Release files / flakehound-0.1.0.tar.gz

Download URL flakehound-0.1.0.tar.gz
Size 70.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d08d4d314f2d43fdd5d7369e5536c0299baad1eb36106c0f50642409ecba4efa
BLAKE2b-256 checksum
How to use checksums
005b15baa4c94f3fe06614cab7f3da91ad0c4fae9bc1c4504af38f82c2874248
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / flakehound-0.1.0-py3-none-any.whl

Download URL flakehound-0.1.0-py3-none-any.whl
Size 70.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd86740969665f63fb2d0ca33e2fb618240688c33093792aee88cf6a5fc7d1e6
BLAKE2b-256 checksum
How to use checksums
6e9f40b1af53d98d548389251318318514fb531cc7a57787fcbd4ec61cb7bb3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for flakehound 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for flakehound-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page