summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-08-27 22:35:14 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-08-27 22:35:14 (GMT)
commit079fc7faff3cee1c68aee3ce0ca2c4ee18b72aab (patch)
treeb783d684fd15a3cf643244321fe14b1978b704aa /Lib/unittest
parentdcc47c6064cfa7b44a13853f14e4819185c8f2a2 (diff)
parented599b7c84ee216866f4f8a69b5f25dbc5cb4618 (diff)
downloadcpython-079fc7faff3cee1c68aee3ce0ca2c4ee18b72aab.zip
cpython-079fc7faff3cee1c68aee3ce0ca2c4ee18b72aab.tar.gz
cpython-079fc7faff3cee1c68aee3ce0ca2c4ee18b72aab.tar.bz2
Issue #21112: Fix regression in unittest.expectedFailure on subclasses.
Patch from Berker Peksag.
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py7
-rw-r--r--Lib/unittest/test/test_skipping.py33
2 files changed, 38 insertions, 2 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index a4a0a1f..ac8d67d 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -583,8 +583,11 @@ class TestCase(object):
finally:
result.stopTest(self)
return
- expecting_failure = getattr(testMethod,
- "__unittest_expecting_failure__", False)
+ expecting_failure_method = getattr(testMethod,
+ "__unittest_expecting_failure__", False)
+ expecting_failure_class = getattr(self,
+ "__unittest_expecting_failure__", False)
+ expecting_failure = expecting_failure_class or expecting_failure_method
outcome = _Outcome(result)
try:
self._outcome = outcome
diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py
index 807510f..71f7b70 100644
--- a/Lib/unittest/test/test_skipping.py
+++ b/Lib/unittest/test/test_skipping.py
@@ -120,6 +120,39 @@ class Test_TestSkipping(unittest.TestCase):
self.assertEqual(result.expectedFailures[0][0], test)
self.assertTrue(result.wasSuccessful())
+ def test_expected_failure_with_wrapped_class(self):
+ @unittest.expectedFailure
+ class Foo(unittest.TestCase):
+ def test_1(self):
+ self.assertTrue(False)
+
+ events = []
+ result = LoggingResult(events)
+ test = Foo("test_1")
+ test.run(result)
+ self.assertEqual(events,
+ ['startTest', 'addExpectedFailure', 'stopTest'])
+ self.assertEqual(result.expectedFailures[0][0], test)
+ self.assertTrue(result.wasSuccessful())
+
+ def test_expected_failure_with_wrapped_subclass(self):
+ class Foo(unittest.TestCase):
+ def test_1(self):
+ self.assertTrue(False)
+
+ @unittest.expectedFailure
+ class Bar(Foo):
+ pass
+
+ events = []
+ result = LoggingResult(events)
+ test = Bar("test_1")
+ test.run(result)
+ self.assertEqual(events,
+ ['startTest', 'addExpectedFailure', 'stopTest'])
+ self.assertEqual(result.expectedFailures[0][0], test)
+ self.assertTrue(result.wasSuccessful())
+
def test_expected_failure_subtests(self):
# A failure in any subtest counts as the expected failure of the
# whole test.