Issue #14664: It is now possible to use @unittest.skip{If,Unless} on a test class...
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 25 Apr 2012 12:56:46 +0000 (14:56 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 25 Apr 2012 12:56:46 +0000 (14:56 +0200)
Lib/unittest/case.py
Lib/unittest/test/test_skipping.py
Misc/NEWS

index 3133907e4a9a39cbbc65bc7ff6bd137a0de5ca86..e627ccaaf19fef96197e29545db06f0eaa7c07ae 100644 (file)
@@ -62,7 +62,7 @@ def skip(reason):
     Unconditionally skip a test.
     """
     def decorator(test_item):
-        if not (isinstance(test_item, type) and issubclass(test_item, TestCase)):
+        if not isinstance(test_item, type):
             @functools.wraps(test_item)
             def skip_wrapper(*args, **kwargs):
                 raise SkipTest(reason)
index b5924646c19272554a9b538f712ad05dc65df4e3..952240eeededd5bc8167a56eff39d5fbaba36ccd 100644 (file)
@@ -66,6 +66,21 @@ class Test_TestSkipping(unittest.TestCase):
         self.assertEqual(result.skipped, [(test, "testing")])
         self.assertEqual(record, [])
 
+    def test_skip_non_unittest_class(self):
+        @unittest.skip("testing")
+        class Mixin:
+            def test_1(self):
+                record.append(1)
+        class Foo(Mixin, unittest.TestCase):
+            pass
+        record = []
+        result = unittest.TestResult()
+        test = Foo("test_1")
+        suite = unittest.TestSuite([test])
+        suite.run(result)
+        self.assertEqual(result.skipped, [(test, "testing")])
+        self.assertEqual(record, [])
+
     def test_expected_failure(self):
         class Foo(unittest.TestCase):
             @unittest.expectedFailure
index 08254d4dda3367e899dbe435a1407d1f225509f9..2d50fe1c3cde1d03d0c1f04674fdcc84fa7feb3c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -56,6 +56,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14664: It is now possible to use @unittest.skip{If,Unless} on a
+  test class that doesn't inherit from TestCase (i.e. a mixin).
+
 - Issue #14160: TarFile.extractfile() failed to resolve symbolic links when
   the links were not located in an archive subdirectory.