testflakes
testflakes

how testflakes fits in

Install

consolepip install testflakes

Score

For each test it counts flips: the times its outcome changed from one run to the next one it appeared in.

score = flips / (runs - 1)

the failure count is printed next to the score

A skipped run is dropped from the sequence rather than counted as a change, so a temporarily disabled test does not look flaky. A test that is missing from a run (date-filtered, sharded) is skipped too.

Use

pythonfrom testflakes import flakiness, newly_failing, parse_runs

runs = parse_runs(["monday.xml", "tuesday.xml", "wednesday.xml"])
for stat in flakiness(runs, min_runs=3)[:10]:
    print(f"{stat.node_id:50} {stat.score:.2f} failures={stat.failures}")

regressions = newly_failing(runs[-2], runs[-1])
consoletestflakes reports/*.xml --top 10 --min-runs 5      # the table above
testflakes reports/*.xml --json                      # for a dashboard
testflakes yesterday.xml today.xml --new             # what broke, exit 1 if anything

--new is the CI gate: it prints the tests that fail today and were not failing before, and exits non-zero, so a flaky suite cannot hide a real regression behind a retry.

Limits

first (reports/*.xml is already sorted by name if you name them by date).

That is a measurement, not a bug: collect more runs (--min-runs exists for the opposite problem).

Development

consolepython -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/pytest

The suite covers every line of the package (pytest --cov --cov-branch), and the examples in the docstrings run as tests through --doctest-modules.

License

MIT.

Other libraries here

One problem each, standard library only, no runtime dependencies.