python
config_error
ai_generated
true
CoverageWarning:模块 myapp 从未被导入。(module-not-imported) CoverageWarning:未收集到数据。(no-data-collected)
CoverageWarning: Module myapp was never imported. (module-not-imported) CoverageWarning: No data was collected. (no-data-collected)
ID: python/pytest-coverage-source-missing
80%修复率
87%置信度
0证据数
2024-09-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 5.x | active | — | — | — |
| 6.x | active | — | — | — |
| 7.x | active | — | — | — |
根因分析
pytest-cov 指向的源路径与可导入的包名不匹配,或者测试从未导入该包(例如仅测试导入了不同顶层名称的子模块)。
English
pytest-cov was pointed at a source path that doesn't match the importable package name, or tests never import the package (e.g., only test submodules that import a different top-level name).
解决方案
-
95% 成功率
pytest --cov=myapp --cov-report=term-missing tests/
-
92% 成功率
# pyproject.toml [tool.coverage.run] source = ["myapp"] branch = true
-
85% 成功率
# tests/conftest.py import myapp # noqa: F401 ensures coverage sees the package
无效尝试
常见但无效的做法:
-
90% 失败
Branch coverage doesn't fix missing source mapping.
-
90% 失败
Threshold doesn't affect data collection.
-
85% 失败
Extra deps don't fix path/name mismatch.