Skip to content
Latchkey

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=90

Common 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

  1. Generate a report to see which lines are missing coverage.
  2. Add tests that exercise them until the total clears the threshold.
  3. Re-run the coverage gate.
Terminal
pytest --cov=myapp --cov-report=term-missing

Measure 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 = true

How to prevent it

  • Keep tests in step with new code so coverage stays above the gate.
  • Configure source and combine parallel coverage correctly.
  • Adjust fail_under deliberately, not to mask missing tests.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →