python
config_error
ai_generated
true
运行时错误:因为 TestCase 子类没有 __test__ 属性,setUpClass 未被调用
RuntimeError: setUpClass is not called for TestCase subclass because it has no __test__ attribute
ID: python/unittest-setupclass-order-error
80%修复率
80%置信度
0证据数
2024-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
根因分析
当测试类名以 'test' 开头但缺少 __test__ 属性时,unittest 将其视为非测试类
English
当测试类名以 'test' 开头但缺少 __test__ 属性时,unittest 将其视为非测试类
解决方案
-
90% 成功率
确保类继承自 unittest.TestCase,并命名以 test 开头
-
70% 成功率
自定义 loader 加载测试类,指定 loadTestsFromTestCase
无效尝试
常见但无效的做法:
-
40% 失败
unittest 框架仍会因其他原因跳过该类
-
60% 失败
如果类没有正确继承 TestCase,仍会失败