# 覆盖率失败：总计 78.42 低于 fail-under=80.00

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

## 根因

pytest-cov 的 --cov-fail-under 强制最低覆盖率；测得的总覆盖率低于配置阈值，即使所有测试通过也会失败。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   # pyproject.toml
[tool.coverage.run]
source = ["myapp"]
omit = ["myapp/migrations/*", "*/tests/*"]

[tool.coverage.report]
fail_under = 80
show_missing = true
   ```
2. **** (92% 成功率)
   ```
   pytest --cov=myapp --cov-report=term-missing --cov-fail-under=80
# Focus on 'Missing' column to add tests
   ```

## 无效尝试

- **** — Hides untested code and defeats the purpose of the gate; reviewers reject blanket pragma usage. (80% 失败率)
- **** — Removes the gate entirely; regressions slip through and the metric becomes meaningless. (85% 失败率)
