python
config_error
ai_generated
true
CoverageWarning: 未收集到任何数据。(no-data-collected) warnings.warn("未收集到任何数据。", CoverageWarning)
CoverageWarning: No data was collected. (no-data-collected) warnings.warn("No data was collected.", CoverageWarning)
ID: python/pytest-cov-no-data-collected-warning
80%修复率
84%置信度
0证据数
2024-11-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
coverage 已启动但从未停止,或传给 `--cov` 的源路径不匹配任何已导入模块。常见于测试导入的是已安装副本而非 CWD 中的包,或 `--cov=src` 不存在。
English
coverage was started but never stopped, or the source path passed to `--cov` does not match any imported module. Common when tests import a different installed copy of the package than the one in CWD, or when `--cov=src` doesn't exist.
解决方案
-
93% 成功率
pip install -e . pytest --cov=myapp --cov-report=term-missing # or pytest --cov=src/myapp
-
90% 成功率
# pyproject.toml [tool.coverage.run] source = ["myapp"] [tool.pytest.ini_options] addopts = "--cov --cov-report=term-missing"
无效尝试
常见但无效的做法:
-
70% 失败
The report has no data to display; it just prints an empty table.
-
80% 失败
Two coverage processes conflict; the .coverage file is corrupted or overwritten.