# 断言错误：0 != 1：子测试失败

- **ID:** `python/unittest-subtest-failure-not-reported`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

子测试失败未被正确报告，因为 subTest 块没有正确引发断言错误。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   for i in range(5):
    with self.subTest(i=i):
        self.assertEqual(i, 0)
   ```
2. **** (90% 成功率)
   ```
   @pytest.mark.parametrize('i', range(5))
def test_foo(i):
    assert i == 0
   ```

## 无效尝试

- **** — This loses granularity of test reporting. (70% 失败率)
- **** — This may swallow the exception and not mark the test as failed. (80% 失败率)
