]> granicus.if.org Git - python/commitdiff
bpo-34596: Fallback to a default reason when @unittest.skip is uncalled (GH-9082...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 9 Sep 2019 15:01:15 +0000 (08:01 -0700)
committerMichael Foord <voidspace@users.noreply.github.com>
Mon, 9 Sep 2019 15:01:14 +0000 (17:01 +0200)
* 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 d5fd75c53fad7049fc640c9a6162d35f0c5bea03)

Co-authored-by: Naitree Zhu <Naitreey@gmail.com>
Lib/unittest/case.py
Lib/unittest/test/test_skipping.py
Misc/NEWS.d/next/Tests/2018-09-07-01-18-27.bpo-34596.r2-EGd.rst [new file with mode: 0644]

index b363c635100726b4246feeb6af75456325b04a50..b639c64d02a7aac4c2d292c194a2df71f4858414 100644 (file)
@@ -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):
index 71f7b70e479d2e508c242fa8102a0676cf32b5ad..1c178a95f750ffda0e37c0f4853178688647e7ff 100644 (file)
@@ -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()
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 (file)
index 0000000..156e8aa
--- /dev/null
@@ -0,0 +1,2 @@
+Fallback to a default reason when :func:`unittest.skip` is uncalled. Patch by
+Naitree Zhu.