]> granicus.if.org Git - python/commitdiff
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 15:31:12 +0000 (17:31 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 25 Apr 2012 15:31:12 +0000 (17:31 +0200)
Lib/unittest/case.py
Lib/unittest/test/test_skipping.py
Misc/NEWS

index 4b3839e95c26508d9b2dfc0b8a7c6e5585148df1..18dee02675794a5525ec0950c955fcb7e83acb90 100644 (file)
@@ -6,6 +6,7 @@ import functools
 import difflib
 import pprint
 import re
+import types
 import warnings
 
 from . import result
@@ -55,7 +56,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, types.ClassType)):
             @functools.wraps(test_item)
             def skip_wrapper(*args, **kwargs):
                 raise SkipTest(reason)
index 05958d6a31ef6c626cabb17cc11db30dcadfbca4..d6639d17e55ad79fa8af6b145263f389ad422cf2 100644 (file)
@@ -66,6 +66,36 @@ class Test_TestSkipping(unittest.TestCase):
         self.assertEqual(result.skipped, [(test, "testing")])
         self.assertEqual(record, [])
 
+    def test_skip_non_unittest_class_old_style(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_skip_non_unittest_class_new_style(self):
+        @unittest.skip("testing")
+        class Mixin(object):
+            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 1e088c03e0593545cd88543800778cb11f568279..a69ad3ed4d60d55b2e488c82100a7266adcd2781 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.