python
type_error
ai_generated
true
类型错误:skip()函数需要1个参数,但给了0个
TypeError: skip() takes exactly 1 argument (0 given)
ID: python/unittest-skip-decorator-error
80%修复率
90%置信度
0证据数
2024-04-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
根因分析
在unittest中,@unittest.skip装饰器必须提供一个原因字符串,如果省略则报错。
English
在unittest中,@unittest.skip装饰器必须提供一个原因字符串,如果省略则报错。
解决方案
-
100% 成功率
@unittest.skip('暂时跳过') -
95% 成功率
def test_foo(self): self.skipTest('原因')
无效尝试
常见但无效的做法:
-
60% 失败
skipIf也需要条件参数,不是无参数跳过
-
70% 失败
删除装饰器会导致测试执行,而不是跳过