python
type_error
ai_generated
true
TypeError: skip() missing 1 required positional argument: 'reason'
ID: python/unittest-skip-decorator-syntax-error
80%Fix Rate
85%Confidence
0Evidence
2024-06-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
Root Cause
在unittest中,@unittest.skip装饰器需要提供一个原因字符串,如果忘记提供,会抛出TypeError。
generic中文
unittest的skip装饰器必须传入reason参数,否则报错。
Workarounds
-
100% success
@unittest.skip('暂时跳过') def test_example(self): pass -
100% success
@pytest.mark.skip(reason='暂时跳过') def test_example(): pass
Dead Ends
Common approaches that don't work:
-
70% fail
测试将不再跳过,可能执行失败。
-
80% fail
skipIf也需要条件参数,不解决缺失reason的问题。