diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-25 17:31:12 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-25 17:31:12 +0200 |
commit | 381531671435531e24f8f39745058e0f62165209 (patch) | |
tree | a61edc1a90ebbdc671eec96193de84bc19ae8ec2 | |
parent | 00086bb7e8c86cd7a45bc087cdf2485714ae23d7 (diff) | |
download | cpython-git-381531671435531e24f8f39745058e0f62165209.tar.gz |
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).
-rw-r--r-- | Lib/unittest/case.py | 3 | ||||
-rw-r--r-- | Lib/unittest/test/test_skipping.py | 30 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 35 insertions, 1 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 4b3839e95c..18dee02675 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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) diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py index 05958d6a31..d6639d17e5 100644 --- a/Lib/unittest/test/test_skipping.py +++ b/Lib/unittest/test/test_skipping.py @@ -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 @@ -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. |