pytest coverage "fail-under" threshold in CI
Coverage measured your run and the total percentage fell below the fail_under threshold you configured. The tests passed, but the coverage gate fails the build on purpose.
What this error means
After tests pass, the step fails with "Coverage failure: total of N is less than fail-under=M" and a non-zero exit.
pytest
Required test coverage of 90% not reached. Total coverage: 84.21%
Coverage failure: total of 84 is less than fail-under=90Common causes
New uncovered code lowered the total
Added code without tests dragged overall coverage below the threshold.
Coverage measured the wrong scope
A misconfigured source/--cov target or parallel runs not combined can under-report coverage.
How to fix it
Add tests for the uncovered lines
- Generate a report to see which lines are missing coverage.
- Add tests that exercise them until the total clears the threshold.
- Re-run the coverage gate.
Terminal
pytest --cov=myapp --cov-report=term-missingMeasure the right source and combine parallel data
Point coverage at your package and combine data from parallel/xdist runs before checking the threshold.
.coveragerc
[coverage:run]
source = myapp
parallel = trueHow to prevent it
- Keep tests in step with new code so coverage stays above the gate.
- Configure
sourceand combine parallel coverage correctly. - Adjust
fail_underdeliberately, not to mask missing tests.
Related guides
pytest exit code 5 (no tests ran) in CIFix pytest exit code 5 in CI - pytest collected no tests and returns 5, which fails the job even though no te…
pytest "collected 0 items" in CIFix pytest "collected 0 items" in CI - pytest ran but discovered no tests, usually because of naming, rootdir…
tox "ERROR: environment failed" in CIFix tox "ERROR: py312: failed" / "InvocationError" in CI - a tox environment's commands or setup returned non…