November 19, 2026 · Ihor Stefaniv · 2 min read
Flaky tests: why automated tests flicker and how to fix them
A test that fails one run in ten teaches the team to ignore red builds. The six usual causes, how to find which one you have, and a quarantine policy that actually ends.
Why flaky tests are worse than no tests
A flaky test passes and fails with no change in the code. The damage isn't the one failure — it's the habit it builds: "it's red again, just re-run it". Once the team stops trusting red, real regressions slip through.
The six usual causes
| Cause | Symptom | Fix |
|---|---|---|
| Timing, sleep | Fails more on slow CI agents | Wait for a condition (visible, response received), never a fixed pause |
| Shared data | Fails when run in parallel | Each test creates its own data with a unique prefix |
| Run order | Passes alone, fails in the suite | Remove dependencies between tests; run in random order to prove it |
| Environment | Many tests fail at once | Health-check the environment before the run; mock unstable third parties |
| Time and time zones | Fails around midnight or month end | Freeze the clock in tests; store and compare in UTC |
| Animations, rendering | Clicks land on a moving element | Disable animations in test mode; assert the final state |
How to find the cause
- Look at the history. When did it start? Which agent, browser, time of day?
- Read the trace, not just the error. A Playwright trace or a screenshot at the moment of failure usually shows the real story.
- Reproduce under stress. Run the test 50 times in a loop, in parallel, with network throttling. Flakiness that appears once a week shows up in minutes.
- Check the product, too. Sometimes the "flaky test" is a real race condition in the application — and that's the most valuable bug of the month.
npx playwright test promo.spec.ts --repeat-each=50 --workers=8
pytest tests/api/test_promo.py --count=50 -n 8 # pytest-repeat + pytest-xdist
Retries are a band-aid
One retry in CI for UI tests is acceptable if every retry is logged and a test that needed it is reported as flaky. Unlimited retries turn your suite into a slot machine.
A quarantine policy that ends
- A flaky test moves to a quarantine tag within a day, so it stops blocking merges.
- It gets an owner and a deadline (a week, not "someday").
- The quarantine suite still runs nightly, so you see when it's fixed.
- An empty quarantine is the goal; a growing one is a process problem to raise in the retro.
More on suite-level stability in a stable, fast automated test suite.