mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Fixes Issue #20165: The unittest module no longer considers tests marked with
@expectedFailure successful if they pass.
This commit is contained in:
parent
b599c61179
commit
5a6d4bf671
4 changed files with 17 additions and 5 deletions
|
|
@ -1772,6 +1772,10 @@ Loading and running tests
|
||||||
Return ``True`` if all tests run so far have passed, otherwise returns
|
Return ``True`` if all tests run so far have passed, otherwise returns
|
||||||
``False``.
|
``False``.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.4
|
||||||
|
Returns ``False`` if there were any :attr:`unexpectedSuccesses`
|
||||||
|
from tests marked with the :func:`expectedFailure` decorator.
|
||||||
|
|
||||||
|
|
||||||
.. method:: stop()
|
.. method:: stop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,11 +156,16 @@ class TestResult(object):
|
||||||
self.unexpectedSuccesses.append(test)
|
self.unexpectedSuccesses.append(test)
|
||||||
|
|
||||||
def wasSuccessful(self):
|
def wasSuccessful(self):
|
||||||
"Tells whether or not this result was a success"
|
"""Tells whether or not this result was a success."""
|
||||||
return len(self.failures) == len(self.errors) == 0
|
# The hasattr check is for test_result's OldResult test. That
|
||||||
|
# way this method works on objects that lack the attribute.
|
||||||
|
# (where would such result intances come from? old stored pickles?)
|
||||||
|
return ((len(self.failures) == len(self.errors) == 0) and
|
||||||
|
(not hasattr(self, 'unexpectedSuccesses') or
|
||||||
|
len(self.unexpectedSuccesses) == 0))
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"Indicates that the tests should be aborted"
|
"""Indicates that the tests should be aborted."""
|
||||||
self.shouldStop = True
|
self.shouldStop = True
|
||||||
|
|
||||||
def _exc_info_to_string(self, err, test):
|
def _exc_info_to_string(self, err, test):
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ class Test_TestSkipping(unittest.TestCase):
|
||||||
['startTest', 'addUnexpectedSuccess', 'stopTest'])
|
['startTest', 'addUnexpectedSuccess', 'stopTest'])
|
||||||
self.assertFalse(result.failures)
|
self.assertFalse(result.failures)
|
||||||
self.assertEqual(result.unexpectedSuccesses, [test])
|
self.assertEqual(result.unexpectedSuccesses, [test])
|
||||||
self.assertTrue(result.wasSuccessful())
|
self.assertFalse(result.wasSuccessful())
|
||||||
|
|
||||||
def test_unexpected_success_subtests(self):
|
def test_unexpected_success_subtests(self):
|
||||||
# Success in all subtests counts as the unexpected success of
|
# Success in all subtests counts as the unexpected success of
|
||||||
|
|
@ -182,7 +182,7 @@ class Test_TestSkipping(unittest.TestCase):
|
||||||
'addUnexpectedSuccess', 'stopTest'])
|
'addUnexpectedSuccess', 'stopTest'])
|
||||||
self.assertFalse(result.failures)
|
self.assertFalse(result.failures)
|
||||||
self.assertEqual(result.unexpectedSuccesses, [test])
|
self.assertEqual(result.unexpectedSuccesses, [test])
|
||||||
self.assertTrue(result.wasSuccessful())
|
self.assertFalse(result.wasSuccessful())
|
||||||
|
|
||||||
def test_skip_doesnt_run_setup(self):
|
def test_skip_doesnt_run_setup(self):
|
||||||
class Foo(unittest.TestCase):
|
class Foo(unittest.TestCase):
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #20165: The unittest module no longer considers tests marked with
|
||||||
|
@expectedFailure successful if they pass.
|
||||||
|
|
||||||
- Issue #18574: Added missing newline in 100-Continue reply from
|
- Issue #18574: Added missing newline in 100-Continue reply from
|
||||||
http.server.BaseHTTPRequestHandler. Patch by Nikolaus Rath.
|
http.server.BaseHTTPRequestHandler. Patch by Nikolaus Rath.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue