# FAILED tests/test_math.py::TestMath::test_add - AssertionError: 1 != 2
子测试失败: 
  test_add (test_math.TestMath.test_add) (i=1)
AssertionError: 1 != 2

- **ID:** `python/pytest-subtests-unittest-count`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

unittest 的 subTest 失败会被 pytest 报告，但在使用较旧 pytest 版本或未正确配置 pytest-subtests 插件时，不总是作为独立失败计入 JUnit XML 或退出码。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.4 | active | — | — |
| 8.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Install pytest-subtests:
  pip install pytest-subtests
Subtest failures then appear as separate test outcomes in reports.
   ```
2. **** (85% 成功率)
   ```
   Upgrade pytest to >= 7.4 which improved subTest reporting and exit codes.
   ```

## 无效尝试

- **** — Changes test IDs and reporting; may break CI dashboards that key on names. (60% 失败率)
- **** — Reimplements subTest poorly; loses per-case reporting. (80% 失败率)
