# FAILED tests/test_math.py::test_ops - AssertionError: 1 != 2

- **ID:** `python/pytest-subtests-not-counted`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 unittest.TestCase 内使用 `self.subTest(...)` 时，子测试不会阻止父测试继续执行，但父测试仍报告为 FAILED。开发者期望每个子测试作为独立的测试用例出现。

## 版本兼容性

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

## 解决方案

1. **** (98% 成功率)
   ```
   Use pytest's parametrize instead for per-case reporting:

import pytest

@pytest.mark.parametrize('a,b,expected', [(1,1,2),(2,2,4)])
def test_add(a, b, expected):
    assert a + b == expected
   ```
2. **** (90% 成功率)
   ```
   Install pytest-subtests to surface each subTest as its own result:

pip install pytest-subtests

# now each subTest failure is reported individually
   ```

## 无效尝试

- **** — Loses the loop-based data-driven style; verbose but works, so it is not really a dead end—more of a workaround. (30% 失败率)
- **** — Raises immediately, aborting remaining subtests and defeating the purpose of subTest. (90% 失败率)
