Skip to content

Commit

Permalink
Issue python#14664: It is now possible to use @unittest.skip{If,Unles…
Browse files Browse the repository at this point in the history
…s} on a test class that doesn't inherit from TestCase (i.e. a mixin).
  • Loading branch information
pitrou committed Apr 25, 2012
1 parent c2ad0aa commit b05ac86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/unittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions Lib/unittest/test/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ def test_1(self):
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
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit b05ac86

Please sign in to comment.