New A profiler built for pytest suites · open source

Find out why your test suite is slow.

flakytest profiles every test in your pytest suite and shows where its time goes: setup or call, which fixture, database, network, password hashing, sleeps, and the exact lines in your code. Then it tells you what to fix first.

$ pip install flakytest
$ pytest --flakytest-profile

Free and local. No account needed. Python 3.11+, any pytest, works with xdist.

Knows the slow paths of Djangopytest-djangoSQLAlchemyFastAPIfactory_boyrequests & httpxpytest-xdist
How it works

One flag. Every test explained.

A sampling profiler (tachyon on Python 3.15, py-spy before that) watches the whole run. Every sample is attributed to the test and phase it belongs to, so the numbers add up to pytest's exact durations.

1

Run your suite

pytest --flakytest-profile, or flakytest run. Your tests, your machine, your settings. Nothing to change in the code.

2

Open the report

Every test with its time split into setup, call and teardown, fixtures, database, network, hashing, sleeps and the lines of your code that cost the most.

3

Fix the right thing

"Fix next" ranks concrete changes by the seconds they save per run, with the exact setting, fixture or line to change.

~/shop — pytest --flakytest-profile
========================= 812 passed in 84.20s =========================
flakytest profiled 812 tests (tachyon, 1000 Hz, 81,234 samples)

  Where the time goes    db 46%  password_hashing 13%  factories 9%  sleep 4%

  Fix next
  1. Use a fast password hasher in tests              saves 40.1s
  2. Create shared data in setUpTestData, not setUp   saves 22.7s
  3. Reuse the test database (--reuse-db)             saves  9.1s
  4. Repeated queries (N+1) in OrderListView          saves  4.8s

  Report: .flakytest/runs/8c3f…/report.html
What you get

Not a flame graph. Answers.

Profilers tell you which functions are hot. flakytest tells you which test is slow, why, and what to do about it.

Every test, broken down

Exact setup, call and teardown times, every fixture it ran, and its time by category: database, network, password hashing, migrations, factories, sleep, templates and more.

The exact lines

Hot lines point at your code, not at Django internals: the factory, the self.client.login(), the time.sleep in a retry loop.

Queries and N+1s

Query counts per test from Django and SQLAlchemy, with the repeated queries that give away an N+1, and how long they took.

Fix next, ranked

Suggestions that know the tricks: fast password hashers, setUpTestData, --reuse-db, schema-once with savepoints, mocked HTTP, fake timers.

Made for agents too

flakytest report --format markdown gives your coding agent the whole picture in one prompt, and the MCP server lets it ask follow-up questions.

Flakiness, classified

Failures are sorted into flaky (failed and passed on the same commit), caught regressions and tests that were changed to pass.

flakytest cloud · optional

Your CI is not your laptop.

The suite takes 3 minutes locally and 11 in CI, and nobody knows why. Set FLAKYTEST_SECRET_TOKEN and every run uploads its profile, grouped by environment: each CI job and each developer machine.

  • Compare CI with every dev machine, test by test, with the category that explains the difference
  • Suite time trends per environment, and the commit that made it slower
  • Which tests fail in CI, which fail locally, and which are just flaky
  • Mute a flaky test with one click, without a code change
  • An MCP server so your agent can ask "why is CI slow?"
Create a project
# Give your coding agent the flakytest MCP server
$ claude mcp add --transport http flakytest https://flakytest.dev/mcp \
    --header "Authorization: Bearer $FLAKYTEST_SECRET_TOKEN"
# Or hand it the local report, no account needed
$ flakytest report --format markdown
Why is CI slower than my laptop?
compare_environments CI spends +4.1 min per run on network, almost all in test_rates.py: fetch_rate() calls the real API because RATES_CACHE isn't set in CI. Mocking it with responses saves about 3 minutes. Want me to make the change?
For AI agents

Your agent can read a profile now.

Agents are good at fixing slow tests once they know where the time goes. flakytest gives them exactly that, as markdown or through MCP, with node ids, lines and fixes they can act on.

  • list_slow_tests with the reason for each
  • get_test: phases, fixtures, hot lines, queries, flakiness
  • get_insights: the ranked fix-next list
  • compare_environments and list_flaky_tests
FAQ

Questions

Does profiling slow my tests down?

A little. The profiler runs in a separate process and samples the test process (1000 times a second by default), so the overhead is small, and pytest's durations stay exact: samples only decide how each phase's time is split.

Which Python and pytest versions are supported?

Python 3.11 and newer with any recent pytest. On Python 3.15 flakytest uses the built-in tachyon profiler, before that py-spy. pytest-xdist workers are profiled too.

What is uploaded to the cloud?

Only when FLAKYTEST_SECRET_TOKEN is set: the profile document of the run. That's test names, durations, outcomes, failure text, file paths, function names and line numbers, the source lines the report points at, and SQL with its parameters left out. Set FLAKYTEST_UPLOAD=0 to keep a run local.

What about flaky tests?

flakytest started as a flaky test tracker and still is one: it records every result, tells flaky failures apart from caught regressions and changed tests, splits them by CI and local, and lets you mute a test without a code change.

Why only Python?

Because doing one ecosystem well beats doing many badly: the suggestions know Django, SQLAlchemy and pytest specifically. If you want another language, let me know.

Anže Pečar

Hi, I'm Anže.

I've spent more than ten years shipping products with Python teams, and a surprising part of it waiting for test suites. I build flakytest so that a slow or flaky suite stops being a mystery. Questions, ideas or a suite that's slow for no reason? [email protected]

Your next run will tell you what to fix.

$ pip install flakytest && pytest --flakytest-profile