python
type_error
ai_generated
true
类型错误:skip()缺少一个必需的位置参数:'reason'
TypeError: skip() missing 1 required positional argument: 'reason'
ID: python/unittest-skip-decorator-syntax-error
80%修复率
85%置信度
0证据数
2024-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
根因分析
unittest的skip装饰器必须传入reason参数,否则报错。
English
在unittest中,@unittest.skip装饰器需要提供一个原因字符串,如果忘记提供,会抛出TypeError。
解决方案
-
100% 成功率
@unittest.skip('暂时跳过') def test_example(self): pass -
100% 成功率
@pytest.mark.skip(reason='暂时跳过') def test_example(): pass
无效尝试
常见但无效的做法:
-
70% 失败
测试将不再跳过,可能执行失败。
-
80% 失败
skipIf也需要条件参数,不解决缺失reason的问题。