# FAIL 未达到要求的 80% 测试覆盖率。总覆盖率: 74.31%

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

## 根因

pytest-cov 的 --cov-fail-under 将总覆盖率与阈值比较。覆盖率基于整个包计算，包括当前测试子集未执行到的文件。

## 版本兼容性

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

## 解决方案

1. **** (85% 成功率)
   ```
   Scope coverage to changed files in CI:

pytest --cov=app --cov-fail-under=80 --cov-report=term-missing
   ```
2. **** (90% 成功率)
   ```
   Use diff-cover to enforce coverage only on new lines:

diff-cover coverage.xml --compare-branch=origin/main --fail-under=80
   ```

## 无效尝试

- **** — Excludes real code from coverage and hides untested paths rather than testing them. (85% 失败率)
- **** — Disables the gate entirely and lets coverage regress silently. (90% 失败率)
