python type_error ai_generated true

类型错误:skip()函数需要1个参数,但给了0个

TypeError: skip() takes exactly 1 argument (0 given)

ID: python/unittest-skip-decorator-error

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-04-01首次发现

版本兼容性

版本状态引入弃用备注
3.8 active
3.9 active
3.10 active

根因分析

在unittest中,@unittest.skip装饰器必须提供一个原因字符串,如果省略则报错。

English

在unittest中,@unittest.skip装饰器必须提供一个原因字符串,如果省略则报错。

generic

解决方案

  1. 100% 成功率
    @unittest.skip('暂时跳过')
  2. 95% 成功率
    def test_foo(self):
        self.skipTest('原因')

无效尝试

常见但无效的做法:

  1. 60% 失败

    skipIf也需要条件参数,不是无参数跳过

  2. 70% 失败

    删除装饰器会导致测试执行,而不是跳过