Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f99983d

Browse files
committed
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).
2 parents d0bb6aa + b05ac86 commit f99983d

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/unittest/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def skip(reason):
6161
Unconditionally skip a test.
6262
"""
6363
def decorator(test_item):
64-
if not (isinstance(test_item, type) and issubclass(test_item, TestCase)):
64+
if not isinstance(test_item, type):
6565
@functools.wraps(test_item)
6666
def skip_wrapper(*args, **kwargs):
6767
raise SkipTest(reason)

Lib/unittest/test/test_skipping.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ def test_1(self):
6666
self.assertEqual(result.skipped, [(test, "testing")])
6767
self.assertEqual(record, [])
6868

69+
def test_skip_non_unittest_class(self):
70+
@unittest.skip("testing")
71+
class Mixin:
72+
def test_1(self):
73+
record.append(1)
74+
class Foo(Mixin, unittest.TestCase):
75+
pass
76+
record = []
77+
result = unittest.TestResult()
78+
test = Foo("test_1")
79+
suite = unittest.TestSuite([test])
80+
suite.run(result)
81+
self.assertEqual(result.skipped, [(test, "testing")])
82+
self.assertEqual(record, [])
83+
6984
def test_expected_failure(self):
7085
class Foo(unittest.TestCase):
7186
@unittest.expectedFailure

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Core and Builtins
7171
Library
7272
-------
7373

74+
- Issue #14664: It is now possible to use @unittest.skip{If,Unless} on a
75+
test class that doesn't inherit from TestCase (i.e. a mixin).
76+
7477
- Issue #4892: multiprocessing Connections can now be transferred over
7578
multiprocessing Connections. Patch by Richard Oudkerk (sbt).
7679

0 commit comments

Comments
 (0)