# FAIL 未达到 90% 的测试覆盖率要求。总覆盖率：84.32%
ERROR: 覆盖率失败：总计 84.32 低于 fail-under=90.00

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

## 根因

pytest-cov 的 --cov-fail-under 阈值高于实际测量的覆盖率。通常发生在添加了没有测试的新代码时，或者 --cov 中的源路径配置错误导致某些模块显示为 0%。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   pytest --cov=src --cov-report=term-missing --cov-fail-under=0
# then write tests for the missing lines, or:
pytest --cov=src --cov-report=html
open htmlcov/index.html
   ```
2. **** (90% 成功率)
   ```
   pytest --cov=src --cov-fail-under=90 \
  --cov-config=.coveragerc

# .coveragerc
[run]
omit =
    */migrations/*
    */tests/*
    */conftest.py
   ```

## 无效尝试

- **** — Treats the symptom; coverage continues to drift downward and the team loses the safety net. (75% 失败率)
- **** — Excludes code from measurement instead of testing it; reviewers reject the PR and real bugs ship untested. (80% 失败率)
