# 覆盖率警告：未收集到任何数据。（无数据收集）

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

## 根因

pytest-cov插件在测试期间未检测到任何代码执行，可能是因为测试文件未导入源模块，或源代码路径配置错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.1.0 | active | — | — |
| 5.0.0 | active | — | — |

## 解决方案

1. **Ensure test files import the source modules that should be covered** (90% 成功率)
   ```
   In your test file, add: from myproject import mymodule
Then run: pytest --cov=myproject tests/
   ```
2. **Specify the source directory correctly in pytest.ini or pyproject.toml** (85% 成功率)
   ```
   Add to pyproject.toml:
[tool.pytest.ini_options]
addopts = "--cov=src"
cov_source = ["src"]
Then run pytest.
   ```

## 无效尝试

- **Reinstalling pytest-cov via pip** — The issue is not with the installation but with the test configuration or code structure. (80% 失败率)
- **Adding `--cov=myproject` without ensuring the source code is actually executed** — If the tests don't import the source modules, coverage still won't collect data. (60% 失败率)
