python
runtime_error
ai_generated
true
断言错误:在测试方法之前未调用 setUpClass
AssertionError: setUpClass not called before test methods
ID: python/unittest-setupclass-not-called
80%修复率
85%置信度
0证据数
2024-08-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
测试类未继承 unittest.TestCase,或者 setUpClass 定义错误(例如,作为实例方法)。
English
The test class does not inherit from unittest.TestCase, or setUpClass is defined incorrectly (e.g., as an instance method).
解决方案
-
99% 成功率
class TestMyClass(unittest.TestCase): @classmethod def setUpClass(cls): ... -
90% 成功率
@pytest.fixture(scope='class') def setup(): ...
无效尝试
常见但无效的做法:
-
70% 失败
setUp is called for each test, not once for the class.
-
50% 失败
If the class doesn't inherit from TestCase, it won't be recognized.