# 断言错误：在测试方法之前未调用 setUpClass

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

## 根因

测试类未继承 unittest.TestCase，或者 setUpClass 定义错误（例如，作为实例方法）。

## 版本兼容性

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

## 解决方案

1. **** (99% 成功率)
   ```
   class TestMyClass(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        ...
   ```
2. **** (90% 成功率)
   ```
   @pytest.fixture(scope='class')
def setup():
    ...
   ```

## 无效尝试

- **** — setUp is called for each test, not once for the class. (70% 失败率)
- **** — If the class doesn't inherit from TestCase, it won't be recognized. (50% 失败率)
