From: Antoine Pitrou Date: Wed, 25 Apr 2012 12:56:46 +0000 (+0200) Subject: Issue #14664: It is now possible to use @unittest.skip{If,Unless} on a test class... X-Git-Tag: v3.3.0a3~77^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b05ac864f048bfeb184e93be71aebd6223a76eec;p=thirdparty%2FPython%2Fcpython.git 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). --- diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 3133907e4a9a..e627ccaaf19f 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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) diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py index b5924646c192..952240eeeded 100644 --- a/Lib/unittest/test/test_skipping.py +++ b/Lib/unittest/test/test_skipping.py @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index 08254d4dda33..2d50fe1c3cde 100644 --- 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.