python
config_error
ai_generated
true
FAIL 未达到 90% 的测试覆盖率要求。总覆盖率:84.32% ERROR: 覆盖率失败:总计 84.32 低于 fail-under=90.00
FAIL Required test coverage of 90% not reached. Total coverage: 84.32% ERROR: Coverage failure: total of 84.32 is less than fail-under=90.00
ID: python/pytest-cov-fail-under-mismatch
80%修复率
89%置信度
0证据数
2024-12-04首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 5.0 | active | — | — | — |
根因分析
pytest-cov 的 --cov-fail-under 阈值高于实际测量的覆盖率。通常发生在添加了没有测试的新代码时,或者 --cov 中的源路径配置错误导致某些模块显示为 0%。
English
pytest-cov's --cov-fail-under threshold is higher than the actual measured coverage. Common when new code was added without tests, or when source paths in --cov are misconfigured so some modules show as 0%.
解决方案
-
95% 成功率
pytest --cov=src --cov-report=term-missing --cov-fail-under=0 # then write tests for the missing lines, or: pytest --cov=src --cov-report=html open htmlcov/index.html
-
90% 成功率
pytest --cov=src --cov-fail-under=90 \ --cov-config=.coveragerc # .coveragerc [run] omit = */migrations/* */tests/* */conftest.py
无效尝试
常见但无效的做法:
-
75% 失败
Treats the symptom; coverage continues to drift downward and the team loses the safety net.
-
80% 失败
Excludes code from measurement instead of testing it; reviewers reject the PR and real bugs ship untested.