python
config_error
ai_generated
true
覆盖率警告:未收集到任何数据。(无数据收集)
CoverageWarning: No data was collected. (no-data-collected)
ID: python/pytest-cov-missing-coverage-data
80%修复率
82%置信度
0证据数
2024-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.1.0 | active | — | — | — |
| 5.0.0 | active | — | — | — |
根因分析
pytest-cov插件在测试期间未检测到任何代码执行,可能是因为测试文件未导入源模块,或源代码路径配置错误。
English
The pytest-cov plugin did not detect any code execution during tests, possibly because the test files are not importing the source modules, or the source code paths are misconfigured.
解决方案
-
90% 成功率 Ensure test files import the source modules that should be covered
In your test file, add: from myproject import mymodule Then run: pytest --cov=myproject tests/
-
85% 成功率 Specify the source directory correctly in pytest.ini or pyproject.toml
Add to pyproject.toml: [tool.pytest.ini_options] addopts = "--cov=src" cov_source = ["src"] Then run pytest.
无效尝试
常见但无效的做法:
-
Reinstalling pytest-cov via pip
80% 失败
The issue is not with the installation but with the test configuration or code structure.
-
Adding `--cov=myproject` without ensuring the source code is actually executed
60% 失败
If the tests don't import the source modules, coverage still won't collect data.