python
config_error
ai_generated
true
FAIL Required test coverage of 80% not reached. Total coverage: 74.31%
ID: python/pytest-cov-fail-under-missing
80%Fix Rate
88%Confidence
0Evidence
2024-05-06First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5.x | active | — | — | — |
| 6.x | active | — | — | — |
Root Cause
pytest-cov --cov-fail-under compares total coverage against the threshold. Coverage is computed on the whole package, including files not exercised by the current test subset.
generic中文
pytest-cov 的 --cov-fail-under 将总覆盖率与阈值比较。覆盖率基于整个包计算,包括当前测试子集未执行到的文件。
Workarounds
-
85% success
Scope coverage to changed files in CI: pytest --cov=app --cov-fail-under=80 --cov-report=term-missing
-
90% success
Use diff-cover to enforce coverage only on new lines: diff-cover coverage.xml --compare-branch=origin/main --fail-under=80
Dead Ends
Common approaches that don't work:
-
85% fail
Excludes real code from coverage and hides untested paths rather than testing them.
-
90% fail
Disables the gate entirely and lets coverage regress silently.