python
runtime_error
ai_generated
true
NameError: name 'setup_method' is not defined
ID: python/nameerror-name-not-defined
80%Fix Rate
85%Confidence
0Evidence
2025-01-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
Root Cause
A test class uses a method like setup_method without defining it, or it is misspelled.
generic中文
测试类使用了如 setup_method 的方法但未定义,或拼写错误。
Workarounds
-
95% success Define setup_method as class method
class TestClass: def setup_method(self): pass -
90% success Use pytest fixture instead
@pytest.fixture(autouse=True) def setup_method(self): pass
Dead Ends
Common approaches that don't work:
-
Defining setup_method inside test function
70% fail
setup_method should be a method of the test class, not nested inside a test.
-
Using setup_method as a fixture
50% fail
setup_method is a unittest convention; pytest uses fixtures instead.