python
config_error
ai_generated
true
FAIL 未达到要求的 80% 测试覆盖率。总覆盖率: 74.31%
FAIL Required test coverage of 80% not reached. Total coverage: 74.31%
ID: python/pytest-cov-fail-under-missing
80%修复率
88%置信度
0证据数
2024-05-06首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 5.x | active | — | — | — |
| 6.x | active | — | — | — |
根因分析
pytest-cov 的 --cov-fail-under 将总覆盖率与阈值比较。覆盖率基于整个包计算,包括当前测试子集未执行到的文件。
English
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.
解决方案
-
85% 成功率
Scope coverage to changed files in CI: pytest --cov=app --cov-fail-under=80 --cov-report=term-missing
-
90% 成功率
Use diff-cover to enforce coverage only on new lines: diff-cover coverage.xml --compare-branch=origin/main --fail-under=80
无效尝试
常见但无效的做法:
-
85% 失败
Excludes real code from coverage and hides untested paths rather than testing them.
-
90% 失败
Disables the gate entirely and lets coverage regress silently.