python
runtime_error
ai_generated
true
AssertionError: setUpClass not called before test methods
ID: python/unittest-setupclass-not-called
80%Fix Rate
85%Confidence
0Evidence
2024-08-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The test class does not inherit from unittest.TestCase, or setUpClass is defined incorrectly (e.g., as an instance method).
generic中文
测试类未继承 unittest.TestCase,或者 setUpClass 定义错误(例如,作为实例方法)。
Workarounds
-
99% success
class TestMyClass(unittest.TestCase): @classmethod def setUpClass(cls): ... -
90% success
@pytest.fixture(scope='class') def setup(): ...
Dead Ends
Common approaches that don't work:
-
70% fail
setUp is called for each test, not once for the class.
-
50% fail
If the class doesn't inherit from TestCase, it won't be recognized.