# TypeError: 'TestSuite' 对象不可迭代

- **ID:** `python/unittest-testcase-not-iterable`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

代码试图直接遍历 unittest.TestSuite（如 for t in suite），但 TestSuite 并不按预期方式可迭代；测试需通过 suite._tests 访问或使用 TestLoader/TextTestRunner。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Use the loader to discover tests and iterate the returned suite's _tests, or use unittest's runner:

loader = unittest.TestLoader()
suite = loader.discover('tests')
result = unittest.TextTestRunner(verbosity=2).run(suite)
   ```
2. **** (80% 成功率)
   ```
   Access the internal list when needed (with care):

for test in suite._tests:
    print(test)
   ```

## 无效尝试

- **** — TestSuite does not implement __iter__, so list() raises the same TypeError. (90% 失败率)
- **** — run() executes tests and returns a TestResult, not an iterable of tests. (85% 失败率)
