python type_error ai_generated true

TypeError: skip() missing 1 required positional argument: 'reason'

ID: python/unittest-skip-decorator-syntax-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.10 active

Root Cause

在unittest中,@unittest.skip装饰器需要提供一个原因字符串,如果忘记提供,会抛出TypeError。

generic

中文

unittest的skip装饰器必须传入reason参数,否则报错。

Workarounds

  1. 100% success
    @unittest.skip('暂时跳过')
    def test_example(self):
        pass
  2. 100% success
    @pytest.mark.skip(reason='暂时跳过')
    def test_example():
        pass

Dead Ends

Common approaches that don't work:

  1. 70% fail

    测试将不再跳过,可能执行失败。

  2. 80% fail

    skipIf也需要条件参数,不解决缺失reason的问题。