python
type_error
ai_generated
true
TypeError: setUp() takes 1 positional argument but 2 were given
ID: python/unittest-setup-error
80%Fix Rate
88%Confidence
0Evidence
2024-01-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
Root Cause
在 TestCase 类中定义了带参数的 setUp 方法,但 unittest 调用时不传参数
generic中文
在 TestCase 类中定义了带参数的 setUp 方法,但 unittest 调用时不传参数
Workarounds
-
95% success
def setUp(self):
-
70% success
@classmethod def setUpClass(cls):
Dead Ends
Common approaches that don't work:
-
50% fail
unittest 仍会只传 self
-
30% fail
如果方法名不是 setUp,则不会被调用