mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
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).
This commit is contained in:
parent
00086bb7e8
commit
3815316714
3 changed files with 35 additions and 1 deletions
|
@ -6,6 +6,7 @@ import functools
|
||||||
import difflib
|
import difflib
|
||||||
import pprint
|
import pprint
|
||||||
import re
|
import re
|
||||||
|
import types
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from . import result
|
from . import result
|
||||||
|
@ -55,7 +56,7 @@ def skip(reason):
|
||||||
Unconditionally skip a test.
|
Unconditionally skip a test.
|
||||||
"""
|
"""
|
||||||
def decorator(test_item):
|
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)
|
@functools.wraps(test_item)
|
||||||
def skip_wrapper(*args, **kwargs):
|
def skip_wrapper(*args, **kwargs):
|
||||||
raise SkipTest(reason)
|
raise SkipTest(reason)
|
||||||
|
|
|
@ -66,6 +66,36 @@ class Test_TestSkipping(unittest.TestCase):
|
||||||
self.assertEqual(result.skipped, [(test, "testing")])
|
self.assertEqual(result.skipped, [(test, "testing")])
|
||||||
self.assertEqual(record, [])
|
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):
|
def test_expected_failure(self):
|
||||||
class Foo(unittest.TestCase):
|
class Foo(unittest.TestCase):
|
||||||
@unittest.expectedFailure
|
@unittest.expectedFailure
|
||||||
|
|
|
@ -56,6 +56,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #14160: TarFile.extractfile() failed to resolve symbolic links when
|
||||||
the links were not located in an archive subdirectory.
|
the links were not located in an archive subdirectory.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue