# CoverageWarning: 未收集到数据。(no-data-collected)
WARNING: 未能找到模块 'myapp' 的数据

- **ID:** `python/pytest-coverage-no-data-collected`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

coverage run 指向了错误的源码，或者 pytest 在与 coverage 插桩不同的解释器/子进程中执行。常见于使用 pytest-xdist 但未加 --cov，或测试启动的子进程未被 coverage 追踪。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 5.x | active | — | — |
| 7.x | active | — | — |

## 解决方案

1. **** (94% 成功率)
   ```
   pip install pytest-cov
pytest --cov=myapp --cov-report=term-missing -n auto
   ```
2. **** (85% 成功率)
   ```
   # .coveragerc
[run]
concurrency = multiprocessing
parallel = True
source = myapp
   ```

## 无效尝试

- **** — Broadens the source but if coverage is not started under the same process, still collects nothing. (70% 失败率)
- **** — Correct in principle, but if pytest-xdist is active the workers are separate processes and the main process records no data. (65% 失败率)
