python
config_error
ai_generated
true
覆盖率失败:总计 78.42 低于 fail-under=80.00
Coverage failure: total of 78.42 is less than fail-under=80.00
ID: python/pytest-coverage-threshold-fail
80%修复率
86%置信度
0证据数
2025-03-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 5.0.x | active | — | — | — |
| 6.0.x | active | — | — | — |
根因分析
pytest-cov 的 --cov-fail-under 强制最低覆盖率;测得的总覆盖率低于配置阈值,即使所有测试通过也会失败。
English
pytest-cov's --cov-fail-under enforces a minimum coverage; the measured total is below the configured threshold, failing the run even if all tests pass.
解决方案
-
90% 成功率
# pyproject.toml [tool.coverage.run] source = ["myapp"] omit = ["myapp/migrations/*", "*/tests/*"] [tool.coverage.report] fail_under = 80 show_missing = true
-
92% 成功率
pytest --cov=myapp --cov-report=term-missing --cov-fail-under=80 # Focus on 'Missing' column to add tests
无效尝试
常见但无效的做法:
-
80% 失败
Hides untested code and defeats the purpose of the gate; reviewers reject blanket pragma usage.
-
85% 失败
Removes the gate entirely; regressions slip through and the metric becomes meaningless.