Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/unittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import collections
import contextlib
import traceback
import types

from . import result
from .util import (strclass, safe_repr, _count_diff_all_purpose,
Expand Down Expand Up @@ -98,6 +99,10 @@ def skip_wrapper(*args, **kwargs):
test_item.__unittest_skip__ = True
test_item.__unittest_skip_why__ = reason
return test_item
if isinstance(reason, types.FunctionType):
test_item = reason
reason = ''
return decorator(test_item)
return decorator

def skipIf(condition, reason):
Expand Down
11 changes: 11 additions & 0 deletions Lib/unittest/test/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ def test_1(self):
suite.run(result)
self.assertEqual(result.skipped, [(test, "testing")])

def test_skip_without_reason(self):
class Foo(unittest.TestCase):
@unittest.skip
def test_1(self):
pass

result = unittest.TestResult()
test = Foo("test_1")
suite = unittest.TestSuite([test])
suite.run(result)
self.assertEqual(result.skipped, [(test, "")])

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fallback to a default reason when :func:`unittest.skip` is uncalled. Patch by
Naitree Zhu.