# CoverageWarning: 未收集到任何数据。(no-data-collected)
  warnings.warn("未收集到任何数据。", CoverageWarning)

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

## 根因

coverage 已启动但从未停止，或传给 `--cov` 的源路径不匹配任何已导入模块。常见于测试导入的是已安装副本而非 CWD 中的包，或 `--cov=src` 不存在。

## 版本兼容性

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

## 解决方案

1. **** (93% 成功率)
   ```
   pip install -e .
pytest --cov=myapp --cov-report=term-missing
# or
pytest --cov=src/myapp
   ```
2. **** (90% 成功率)
   ```
   # pyproject.toml
[tool.coverage.run]
source = ["myapp"]

[tool.pytest.ini_options]
addopts = "--cov --cov-report=term-missing"
   ```

## 无效尝试

- **** — The report has no data to display; it just prints an empty table. (70% 失败率)
- **** — Two coverage processes conflict; the .coverage file is corrupted or overwritten. (80% 失败率)
