summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorNaitree Zhu <Naitreey@gmail.com>2019-09-09 14:06:48 (GMT)
committerMichael Foord <voidspace@users.noreply.github.com>2019-09-09 14:06:48 (GMT)
commitd5fd75c53fad7049fc640c9a6162d35f0c5bea03 (patch)
treea5d7e0fc5daeae1188fe18e6bf5541d92aee23c0 /Lib/unittest
parent264e034f990240e2aa379d8484b15b9e70c1fad5 (diff)
downloadcpython-d5fd75c53fad7049fc640c9a6162d35f0c5bea03.zip
cpython-d5fd75c53fad7049fc640c9a6162d35f0c5bea03.tar.gz
cpython-d5fd75c53fad7049fc640c9a6162d35f0c5bea03.tar.bz2
bpo-34596: Fallback to a default reason when @unittest.skip is uncalled (#9082)
* bpo-34596: Fallback to a default reason when @unittest.skip is uncalled * Change default reason to empty string * Fix rst formatting of NEWS entry
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py5
-rw-r--r--Lib/unittest/test/test_skipping.py11
2 files changed, 16 insertions, 0 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 8afb845..bac9789 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -10,6 +10,7 @@ import warnings
import collections
import contextlib
import traceback
+import types
from . import result
from .util import (strclass, safe_repr, _count_diff_all_purpose,
@@ -122,6 +123,10 @@ def skip(reason):
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):
diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py
index 71f7b70..1c178a9 100644
--- a/Lib/unittest/test/test_skipping.py
+++ b/Lib/unittest/test/test_skipping.py
@@ -255,6 +255,17 @@ class Test_TestSkipping(unittest.TestCase):
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()