python
config_error
ai_generated
true
CoverageWarning: 未收集到数据。(no-data-collected) WARNING: 未能找到模块 'myapp' 的数据
CoverageWarning: No data was collected. (no-data-collected) WARNING: Failed to find data for module 'myapp'
ID: python/pytest-coverage-no-data-collected
80%修复率
84%置信度
0证据数
2024-08-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 5.x | active | — | — | — |
| 7.x | active | — | — | — |
根因分析
coverage run 指向了错误的源码,或者 pytest 在与 coverage 插桩不同的解释器/子进程中执行。常见于使用 pytest-xdist 但未加 --cov,或测试启动的子进程未被 coverage 追踪。
English
coverage run was pointed at the wrong source, or pytest is executed under a different interpreter/subprocess than the one coverage instruments. Common when using pytest-xdist without --cov or when tests spawn subprocesses that coverage does not trace.
解决方案
-
94% 成功率
pip install pytest-cov pytest --cov=myapp --cov-report=term-missing -n auto
-
85% 成功率
# .coveragerc [run] concurrency = multiprocessing parallel = True source = myapp
无效尝试
常见但无效的做法:
-
70% 失败
Broadens the source but if coverage is not started under the same process, still collects nothing.
-
65% 失败
Correct in principle, but if pytest-xdist is active the workers are separate processes and the main process records no data.