Flaky Test Quarantine: Let the Failure Rate Decide the Exit
A flaky test quarantine policy: measured entry, a non-blocking lane in pytest, Playwright, Jest and JUnit, owner and expiry, a cap, and exit sized to the rate.
Google reported in 2016 that "about 84% of the transitions we observe from pass to fail involve a flaky test" (Google Testing Blog). Martin Fowler's 2011 quarantine advice warned that tests "keep getting thrown into quarantine and forgotten" (martinfowler.com). A flaky test quarantine keeps red builds trustworthy only when each quarantined test records a measured failure rate, an owner and an expiry, keeps running where it cannot block a merge, and lets that recorded rate decide how many clean runs prove the fix. This guide assumes you already detect flaky tests (four-step triage) and run pytest, Playwright, Jest or JUnit on GitHub Actions; other CI systems need a job that reports results without failing the pipeline.
Table of contents
What GitHub's reruns and Slack's suppression fixed, and what they left open
Taking flaky failures out of the required check, the job that must pass before a pull request can merge (the gate from here on), cut red builds at GitHub and Slack, but each left a problem open.
Entry rule: a 5% to 50% first-attempt failure rate over 10 or more runs
Every entry starts from an issue, as GitLab requires: "Before you quarantine a test, you must have a relevant issue."
Count first attempts and write the run count next to the rate
The failure rate is runs where the test's first attempt failed over runs where it ran, so a pass on a retry counts as a failure. Count main-branch runs only (pushes and scheduled runs): a pull-request run can fail because of the change under review.
The free Flaky test finder reads JUnit, TRX, NUnit, Playwright and CTRF reports without uploading them. Add a test's Retried passes count to the first number in its Fail rate cell: "3 of 20 (15%)" with 1 retried pass is 4 in 20, or 20%. The finder sees a retry only if the report records it (Playwright flaky, Surefire <flakyFailure>, CTRF flaky, or the test listed as failed, then passed); a report of final attempts only understates the rate.
The entry rule: at least 10 main-branch runs in the last 14 days, at a rate from 5% to 50%. That is the flake-dashboard-author skill's candidate query, inside the flaky-test-quarantine skill's band: "between 1% and 50% of runs (above 50% it's not flaky, it's broken; under 1% the noise is acceptable for most projects)". A test at 1% to 5% goes on a watch list and stays in the gate. The floor is 5% because a 2% rate needs 149 clean runs to leave (exit rule).
Keep the run count with the rate: 2 failures in 20 runs could be a true rate from 2.8% to 30.1%, and 12 in 100 from 7.0% to 19.8% (95% Wilson intervals).
Four cases that look flaky but do not enter quarantine
Run quarantined tests on main and nightly, outside the required checks
Quarantine moves a test's failures out of the required checks while the test keeps running in a lane: a CI job that runs only quarantined tests, keeps every result and is never a required check. A 2022 review of 651 articles calls quarantine-then-fix "The most common strategy that has been discussed", and warns that it "could easily mask a real race condition or some other bug" (arXiv:2212.00908). The mechanism decides whether that stays visible:
| Mechanism | Examples | What the required check and the history see |
|---|---|---|
| Skip or disable | Playwright test.fixme() and test.skip(), JUnit @Disabled | Check green; the test stops running, so its history stops |
| Expected failure | pytest non-strict xfail | Check green; the test runs, but JUnit XML logs a failure as <skipped type="pytest.xfail"> and an unexpected pass (XPASS) as an ordinary pass, so the history is mislabeled |
| Separate non-blocking lane | A marker or tag that the required check excludes and a separate job runs | Check green; every run is still recorded |
| Run in place, override the result | Vendor tools, such as Trunk, where a quarantined test "continues running in CI and uploading results" (Trunk docs) | Check green; the vendor keeps the history |
Gradle runs its @Flaky tests "in a nightly CI job" (2022), Atlassian "in branch builds, scheduled jobs, or quarantine pipelines" (2025) and Uber "in non-blocking mode as FYI only" (2024). GitLab's quarantined tests "are excluded from CI pipelines" (GitLab docs), though Luo et al. (FSE 2014) found developers reluctant to @Ignore flaky tests that "may still provide some coverage" (paper).
The lane's runs are the evidence the exit rule needs, gathered without rerunning anything by hand. They also catch worse, as a hypothetical shows: a lane rate that jumps from 12% to 100% is a regression hiding in quarantine.
Skip a test only when running it harms the run: "Use fixme when running the test is slow or crashes" (Playwright docs). Run the lane on pushes to main and on a schedule, never on pull requests. The regression testing guide gives the four-step version; this is the policy in detail.
Build the lane in pytest 9.2 and GitHub Actions
Versions as of November 2026: pytest 9.2.0, Playwright 1.65.1, Jest 30.5.2, JUnit 6.1.3, Gradle 9.9.2 and Maven Surefire 3.6.1, with actions/checkout, actions/setup-python and actions/upload-artifact at @v7. The pytest, Playwright and Jest commands below were run on these versions; the workflow passes actionlint but was not run on GitHub, and the Gradle and Maven lines were only checked against their docs.
Register the marker. [tool.pytest] takes native TOML since pytest 9.0 (configuration), and strict_markers = true makes an unknown marker an error, in -m too (reference), so a typo in -m "not quarantine" stops the run instead of selecting every test.
# pyproject.toml
[tool.pytest]
testpaths = ["tests"]
strict_markers = true
markers = [
"quarantine: flaky test that runs only in the quarantine lane; the reason holds its record",
]Don't call it flaky, which pytest-rerunfailures uses for reruns; the markers guide covers the basics. The record goes in reason:
# tests/test_export.py
import pytest
@pytest.mark.quarantine(reason="Quarantined 2026-11-23 (#1234) - fails ~12% of runs (12/100) on ubuntu-latest; not yet bisected. Re-evaluate by 2026-12-23. Owner: @web-platform.")
def test_export_lists_every_row():
... # the test body stays as it wasThe gate, your required check, runs on pull requests and pushes to main, uploads its JUnit XML (the main-branch reports the entry rule reads), then checks the cap:
# .github/workflows/tests.yml
name: tests
on:
pull_request:
push:
branches: [main]
schedule:
- cron: "0 3 * * *" # nightly lane run
jobs:
gate: # the required check
if: github.event_name != 'schedule'
runs-on: ubuntu-latest
env:
QUARANTINE_CAP: 5
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- run: pip install pytest==9.2.0 # plus your project's dependencies
- run: pytest -m "not quarantine" --junitxml=reports/gate.xml
- if: ${{ !cancelled() }}
uses: actions/upload-artifact@v7
with:
name: junit-gate
path: reports/gate.xml
- name: Quarantine cap
run: |
count=$({ grep -rho '@pytest\.mark\.quarantine' tests || true; } | wc -l)
echo "quarantined: $count (cap: $QUARANTINE_CAP)"
test "$count" -le "$QUARANTINE_CAP"The lane job goes under the same jobs key:
quarantine-lane: # never a required check
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- run: pip install pytest==9.2.0 # plus your project's dependencies
# no rerun options; exit code 5 (no tests collected) counts as a pass
- run: pytest -m quarantine --junitxml=reports/quarantine.xml || [ $? -eq 5 ]
- if: ${{ !cancelled() }}
uses: actions/upload-artifact@v7
with:
name: junit-quarantine
path: reports/quarantine.xmlGitHub recommends if: ${{ !cancelled() }} to "run a job or step regardless of its success or failure" (expressions). continue-on-error: true "Prevents a workflow run from failing when a job fails" (workflow syntax), and exit code 5 means "No tests were collected" (exit codes), so an empty lane stays green.
Gate and lane selectors in pytest, Playwright, Jest and JUnit
Each runner splits the same way; the selector, the commands and the trap that breaks the lane differ.
| Runner | Gate, then lane | What breaks the lane |
|---|---|---|
| pytest 9.2 | pytest -m "not quarantine", then pytest -m quarantine | An empty lane exits 5: treat it as success. Non-strict xfail logs failures as skips, and strict=True fails every pass. |
| Playwright 1.65 | Project gate with grepInvert: /@quarantine/ (skips tests whose title or tag matches), run as npx playwright test --project=gate; then project quarantine with grep: /@quarantine/ and retries: 0, run as npx playwright test --project=quarantine --pass-with-no-tests | A plain npx playwright test runs every project, so the required check would run the quarantine project too: name the project in both jobs. Without --pass-with-no-tests, an empty lane fails with "No tests found". test.fail() fails every passing run, and test.fixme() stops the test running. |
| Jest 30 | npx jest --testPathIgnorePatterns '/node_modules/' '\.quarantine\.test\.', then npx jest --testPathPatterns '\.quarantine\.test\.' --passWithNoTests, with quarantined tests in *.quarantine.test.ts files | Jest's docs describe no tags, so the file name is the selector. The command-line value replaces the /node_modules/ default, so the gate passes it back. An empty lane needs --passWithNoTests, and test.failing fails every passing run. |
| JUnit 6 | Gradle: excludeTags("quarantine") in test, then a second Test task that sets testClassesDirs and classpath from the test source set and calls useJUnitPlatform { includeTags("quarantine") }. Maven: mvn test -DexcludedGroups=quarantine, then mvn test -Dgroups=quarantine | Since Gradle 9.0 only the built-in test task uses the test source set, so a second task without testClassesDirs and classpath finds no tests. @Disabled stops the test running. |
Playwright "will run all projects by default" (projects), and Jest 30 renamed --testPathPattern to --testPathPatterns (upgrade guide). The tag filters come from the Gradle testing guide and Surefire's groups and excludedGroups user properties.
The quarantine record: rate, run count, owner and expiry in the test file
The record lives next to the test, where the next reader sees it and a script can parse it. The Testland flaky-test-quarantine skill writes it as one line: date, issue link, failure rate ("measured, not guessed"), bisect status, a "Re-evaluate by" date and an optional owner. It sets the expiry at 30 days by default, 14 for high-traffic CI and 90 for low-traffic suites. Its examples put the line on test.fixme() or @Disabled, which stop the test; here it goes on the marker or tag, and the test keeps running.
This policy adds two things: the run count next to the rate (~12% of runs (12/100)), and a required owner that names a real team. In Playwright the line is an annotation, { type: 'quarantine', description: '<record>' }; in JUnit and Jest, a comment above the test. GitLab owners must "Acknowledge within 48 hours", and Uber and Atlassian open a ticket with a deadline.
Exit rule: the recorded failure rate sets how many clean runs prove a fix
Clean runs needed at 12%, 5%, 2% and 1% failure rates
Published exit rules use one bar for every test: GitLab's "more than 100 local runs" with the root cause "identified and fixed" (detailed process), Uber's "the test must pass N times consecutively" with N unpublished.
If the fix failed and the test still fails at rate p, it passes n runs in a row with probability (1 - p)^n. For 95% confidence, n = ln(0.05) / ln(1 - p), rounded up (Testland's arithmetic):
| Recorded rate | Clean runs in a row for 95% confidence | Chance an unfixed test passes 100 in a row |
|---|---|---|
| 12% | 24 | about 0.0003% |
| 5% | 59 | 0.6% |
| 2% | 149 | 13.3% |
| 1% | 299 | 36.6% |
A fixed bar errs both ways. A 12% test needs only 24 clean runs, 12 days at two lane runs a day, which fits a 30-day expiry if the fix lands by day 18; 100 runs take 50 days. And 2 failures in 20 (10%) can be a true 2.8%: if lane runs before the fix bring the measured rate down there, the count is 106, past 100.
Before counting, size the exit from the lower of the entry rate and the combined rate: all first-attempt failures over all runs, entry window plus lane runs before the fix. A 12% test (3 in 25) with 10 clean lane runs has a combined 3 of 35, or 8.6%: 34 clean runs. No exit is sized below 1% (299 runs), the skill's floor. A test whose rate falls under 5% still leaves by its count, not the watch-list rule: it entered with an open issue, and only the count shows the fix worked.
Exit also needs a named cause (triage guide). In the week after exit, a first-attempt failure on a main-branch run (pull-request runs don't count) puts the test straight back with its old record, per GitLab's "re-quarantine immediately if failures occur": the one exception to the entry rule.
Check that the lane reaches the count before the expiry date
Lane runs per day, times the days from the fix to the expiry date, must reach the count. With the fix on day one of the period, a nightly lane gives about 30 runs in 30 days: enough for 12% (24), not for 5% (59), which needs two a day. A 14-day expiry needs five a day for 59, and a 2% rate needs 149, five a day for all 30 days. Pushes to main add runs. Short of the count, rerun the fixed commit: Playwright's --repeat-each <N> ("Run each test N times", CLI) or a shell loop over pytest -m quarantine. That cost is why entry starts at 5%.
At each expiry: fix, renew at most twice, or delete
A test leaves as soon as its fix is merged and its lane or repeat runs reach the count (exit rule): remove the marker and close the issue. The expiry date is the deadline for the other two outcomes: on that date, a test still in quarantine is renewed for one more period with an updated rate, at most twice in a row, or deleted. Expiry never lowers the bar. One period plus two renewals caps quarantine at about 90 days by default, 42 on 14-day periods and 270 on 90-day ones.
The flaky-test-quarantine skill in the qa-flake-triage plugin automates the deadline: its scheduled report lists entries past their "Re-evaluate by" date and opens one issue per entry, and its pruning rules cap renewals: "never more than two consecutive renewals". Its script finds entries by test.fixme(; for a marker or tag lane, adapt it to search for Re-evaluate by.
GitLab deletes a long-term quarantined test after "3 months"; Fowler's 2011 cap was "no longer than a week". A test whose feature is gone is deleted at once.
Commit a quarantine cap, then track age, exit outcomes and flakes on the gate
Four numbers keep the quarantine small, and the first is a hard limit:
Watching alone helps: in 2019, a table of slow, fast and flaky tests reduced test flakiness at Spotify from 6% to 4% in two months (Spotify Engineering). The flake-dashboard-author skill's weekly report has a "Quarantined tests" row, to be read alongside the pass rate, and test observability metrics adds the skip count.