# 覆盖率错误：未收集到模块 'my_module' 的数据

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

## 根因

覆盖率插件 (pytest-cov) 未正确配置以测量目标模块，通常是由于缺少 --cov 选项或模块路径不正确。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## 解决方案

1. **Specify the module to measure using --cov flag.** (95% 成功率)
   ```
   pytest --cov=my_module
   ```
2. **Configure coverage in pyproject.toml under [tool.coverage.run] section.** (90% 成功率)
   ```
   [tool.coverage.run]
source = ['my_module']
   ```

## 无效尝试

- **Adding --cov-report=html without specifying --cov** — Coverage data collection requires --cov to specify the module; without it, no data is collected. (80% 失败率)
- **Setting coverage in setup.cfg but not using --cov on command line** — Command-line options override config file; if --cov is missing, coverage may not run. (70% 失败率)
