python
config_error
ai_generated
true
CoverageWarning: 模块 myapp 从未被导入。(module-not-imported)
CoverageWarning: Module myapp was never imported. (module-not-imported)
ID: python/pytest-cov-source-not-found
80%修复率
85%置信度
0证据数
2024-05-09首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.x | active | — | — | — |
| 5.x | active | — | — | — |
| 6.x | active | — | — | — |
根因分析
pytest-cov 使用 --cov=myapp 调用,但测试会话期间从未导入该包,通常是因为测试导入的包名不同或源码路径错误。
English
pytest-cov was invoked with --cov=myapp but the package was never imported during the test session, often because tests import a differently named package or the source path is wrong.
解决方案
-
90% 成功率
pytest --cov=myapp --cov-report=term-missing tests/
-
88% 成功率
# .coveragerc [run] source = src/myapp
无效尝试
常见但无效的做法:
-
80% 失败
Changes the report format only; the module is still never imported so coverage stays at 0%.
-
70% 失败
Marks the module as imported but bypasses the real code paths, producing misleading 100% coverage on empty lines.