python
type_error
ai_generated
true
类型错误:skip() 缺少必需的位置参数:'reason'
TypeError: skip() missing required positional argument: 'reason'
ID: python/unittest-skip-decorator-syntax
80%修复率
88%置信度
0证据数
2026-03-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
根因分析
使用 @unittest.skip 时未提供原因字符串,或将其作为无括号的裸装饰器使用,导致 TypeError。
English
Using @unittest.skip without providing a reason string, or using it as a bare decorator without parentheses, causing a TypeError.
解决方案
-
95% 成功率
Use @unittest.skip('reason') with a string argument, e.g., @unittest.skip('Not implemented yet') -
90% 成功率
Alternatively, use @unittest.skipIf(condition, 'reason') to skip conditionally.
无效尝试
常见但无效的做法:
-
70% 失败
Adding parentheses but no argument (e.g., @unittest.skip()) still fails because reason is required.
-
60% 失败
Using @unittest.skipIf(condition) without a reason also fails because reason is required for skipIf.