Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bd4bed

Browse files
miss-islingtonNaitreey
authored andcommitted
bpo-34596: Fallback to a default reason when @unittest.skip is uncalled (GH-9082) (#15781)
* bpo-34596: Fallback to a default reason when @unittest.skip is uncalled * Change default reason to empty string * Fix rst formatting of NEWS entry (cherry picked from commit d5fd75c) Co-authored-by: Naitree Zhu <[email protected]>
1 parent cabcbbe commit 3bd4bed

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Lib/unittest/case.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import collections
1111
import contextlib
1212
import traceback
13+
import types
1314

1415
from . import result
1516
from .util import (strclass, safe_repr, _count_diff_all_purpose,
@@ -122,6 +123,10 @@ def skip_wrapper(*args, **kwargs):
122123
test_item.__unittest_skip__ = True
123124
test_item.__unittest_skip_why__ = reason
124125
return test_item
126+
if isinstance(reason, types.FunctionType):
127+
test_item = reason
128+
reason = ''
129+
return decorator(test_item)
125130
return decorator
126131

127132
def skipIf(condition, reason):

Lib/unittest/test/test_skipping.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ def test_1(self):
255255
suite.run(result)
256256
self.assertEqual(result.skipped, [(test, "testing")])
257257

258+
def test_skip_without_reason(self):
259+
class Foo(unittest.TestCase):
260+
@unittest.skip
261+
def test_1(self):
262+
pass
263+
264+
result = unittest.TestResult()
265+
test = Foo("test_1")
266+
suite = unittest.TestSuite([test])
267+
suite.run(result)
268+
self.assertEqual(result.skipped, [(test, "")])
258269

259270
if __name__ == "__main__":
260271
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fallback to a default reason when :func:`unittest.skip` is uncalled. Patch by
2+
Naitree Zhu.

0 commit comments

Comments
 (0)