Introducing FlakeFighters, a Pytest plugin for flaky test detection and mitigation
Introduction
When a test fails and it tests code that was not modified, the prevailing wisdom suggests that developers should rerun it. Even though the workflow may go green, the rerun may say nothing about why the test failed or whether the next failure is real. Repeated false alarms also cost compute and teach developers to distrust the test suite. Researchers have proposed better ways to classify a failure as flaky or genuine, yet most of these techniques live in prototypes that handle only Java projects, so Python developers cannot easily try them. My colleagues and I built FlakeFighters to change that — and we describe it in a paper for the tools and datasets track of the International Conference on Automated Software Engineering (Foster et al. 2026) Pytest switch; we applied it to failing workflows from a project with 219,000 lines of code. Read on to see what it does and how the tool fared!
Key Contributions
A Python Home for Proven Classifiers:
FlakeFightersprovides the first Python implementation of theDeFlakeralgorithm, which uses differential coverage to spot a failure that cannot be explained by the code that changed, and the first pytest plugin for failure-log matching and cosine similarity over failure logs. Each technique is a “flakefighter” that can run alone or alongside the others.A New Coverage-Based Detector: We add coverage matching, which compares the lines covered by a newly failing test with the coverage profiles of tests that earlier runs already classified as flaky. A failure counts as flaky when its coverage profile is close enough to those of known flaky tests.
An Extensible Plugin Architecture: The plugin hooks into
Pytestat initialization, collection, execution, and reporting, measures the coverage of each test withCoverage.py, and records every run in a local database so that later runs have history to learn from. Detectors can run in “live” mode, immediately after a failure, or in “post-processing” mode, after the suite finishes, and reruns can be triggered by configurable criteria.CI-Friendly Reporting: Failures that the plugin classifies as flaky are reported as
FLAKYinstead ofFAILED, and an option suppresses flaky failures so that a pipeline whose only failures are flaky does not block a pull request. Results can also be exported to JSON, HTML, and JUnit XML files.
Empirical Results
We evaluated the plugin on failing CI workflows from the home-assistant/core repository, a Python project with close to 87,000 stars, 5,000 contributors, and about 219,000 lines of code. The repository has more than 40,000 CI runs, almost 25,000 of which fail. Our study produced the following results:
The sample: Queries to the GitHub API, run until the hourly rate limit was reached, produced 23 failing workflow runs that contained 30 failing tests across 26 distinct test cases.
Establishing ground truth: We reran each test up to 1,000 times on both the source and the merged commit, stopping early once both a passing and a failing outcome had appeared. The same 12 tests failed at least once on both commits: 6 were flaky and 6 failed on every run, which points to a genuine bug. The remaining 14 failures could not be reproduced, suggesting a problem with the workflow setup rather than with the tests.
Cosine similarity found every flaky test: It identified all 6 flaky failures, with 2 false positives, where a false positive is a test marked flaky even though all 1,000 runs failed.
Differential coverage found a third of them: It classified 2 of the 6 flaky failures correctly and raised no false positives, but it missed failures caused by changes to files that are not code, such as data or configuration files.
Failure log matching found none: The detector depends on tests having been marked flaky in earlier runs, and the logs of a failure are often not identical across runs, so exact matching is hard to satisfy.
Coverage matching struggled: It classified no flaky failure correctly, produced 2 false positives, and could not evaluate 3 tests because every run had the same coverage profile.
Combining the detectors worked best: The combined configuration found all 6 flaky failures with 3 false positives and 3 true negatives. We did not measure the effect on runtime, but we saw no noticeable slowdown during development or evaluation.
Future Work
The case study is a preliminary demonstration rather than a full evaluation, so the paper leaves a comprehensive study for future work. One promising direction is to replace the current rule, which marks a test as flaky when any detector says so, with a “suspiciousness score” that aggregates the individual classifications. Such a score would rank the tests that several detectors flag and would help to reduce the false positives that appear when detectors are combined.
Flaky test detection is a central theme of my research, and this tool puts years of ideas into practice for Python developers. The FlakeFighters plugin is under active development and we plan to maintain it for the foreseeable future, so feedback and contributions are welcome. You can install it from PyPI, read the documentation, or watch the video demonstration. For the details of the techniques and the case study, please read (Foster et al. 2026)