Commit c4d11722 authored by Robert Collins's avatar Robert Collins

Issue #21112: Fix regression in unittest.expectedFailure on subclasses.

Patch from Berker Peksag.
parent 6e56300f
...@@ -563,8 +563,11 @@ class TestCase(object): ...@@ -563,8 +563,11 @@ class TestCase(object):
finally: finally:
result.stopTest(self) result.stopTest(self)
return return
expecting_failure = getattr(testMethod, expecting_failure_method = getattr(testMethod,
"__unittest_expecting_failure__", False) "__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) outcome = _Outcome(result)
try: try:
self._outcome = outcome self._outcome = outcome
......
...@@ -120,6 +120,39 @@ class Test_TestSkipping(unittest.TestCase): ...@@ -120,6 +120,39 @@ class Test_TestSkipping(unittest.TestCase):
self.assertEqual(result.expectedFailures[0][0], test) self.assertEqual(result.expectedFailures[0][0], test)
self.assertTrue(result.wasSuccessful()) 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): def test_expected_failure_subtests(self):
# A failure in any subtest counts as the expected failure of the # A failure in any subtest counts as the expected failure of the
# whole test. # whole test.
......
...@@ -75,6 +75,9 @@ Core and Builtins ...@@ -75,6 +75,9 @@ Core and Builtins
Library Library
------- -------
- Issue #21112: Fix regression in unittest.expectedFailure on subclasses.
Patch from Berker Peksag.
- Issue #24764: cgi.FieldStorage.read_multi() now ignores the Content-Length - Issue #24764: cgi.FieldStorage.read_multi() now ignores the Content-Length
header in part headers. Patch written by Peter Landry and reviewed by Pierre header in part headers. Patch written by Peter Landry and reviewed by Pierre
Quentel. Quentel.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment