[Python-checkins] bpo-34596: Fallback to a default reason when @unittest.skip is uncalled (#9082)

Michael Foord webhook-mailer at python.org
Mon Sep 9 10:06:57 EDT 2019


https://github.com/python/cpython/commit/d5fd75c53fad7049fc640c9a6162d35f0c5bea03
commit: d5fd75c53fad7049fc640c9a6162d35f0c5bea03
branch: master
author: Naitree Zhu <Naitreey at gmail.com>
committer: Michael Foord <voidspace at users.noreply.github.com>
date: 2019-09-09T16:06:48+02:00
summary:

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

files:
A Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst
M Lib/unittest/case.py
M Lib/unittest/test/test_skipping.py

diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 8afb84513590..bac9789c943f 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -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,
@@ -122,6 +123,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):
diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py
index 71f7b70e479d..1c178a95f750 100644
--- a/Lib/unittest/test/test_skipping.py
+++ b/Lib/unittest/test/test_skipping.py
@@ -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()
diff --git a/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst b/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst
new file mode 100644
index 000000000000..156e8aa8945d
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst
@@ -0,0 +1,2 @@
+Fallback to a default reason when :func:`unittest.skip` is uncalled. Patch by
+Naitree Zhu.



More information about the Python-checkins mailing list