[Python-checkins] cpython: Fixes Issue #20165: The unittest module no longer considers tests marked with
gregory.p.smith
python-checkins at python.org
Mon Jan 20 10:11:30 CET 2014
http://hg.python.org/cpython/rev/1e75ab9fd760
changeset: 88579:1e75ab9fd760
user: Gregory P. Smith <greg at krypto.org>
date: Mon Jan 20 01:11:18 2014 -0800
summary:
Fixes Issue #20165: The unittest module no longer considers tests marked with
@expectedFailure successful if they pass.
files:
Doc/library/unittest.rst | 4 ++++
Lib/unittest/result.py | 11 ++++++++---
Lib/unittest/test/test_skipping.py | 4 ++--
Misc/NEWS | 3 +++
4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -1772,6 +1772,10 @@
Return ``True`` if all tests run so far have passed, otherwise returns
``False``.
+ .. versionchanged:: 3.4
+ Returns ``False`` if there were any :attr:`unexpectedSuccesses`
+ from tests marked with the :func:`expectedFailure` decorator.
+
.. method:: stop()
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -156,11 +156,16 @@
self.unexpectedSuccesses.append(test)
def wasSuccessful(self):
- "Tells whether or not this result was a success"
- return len(self.failures) == len(self.errors) == 0
+ """Tells whether or not this result was a success."""
+ # 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):
- "Indicates that the tests should be aborted"
+ """Indicates that the tests should be aborted."""
self.shouldStop = True
def _exc_info_to_string(self, err, test):
diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py
--- a/Lib/unittest/test/test_skipping.py
+++ b/Lib/unittest/test/test_skipping.py
@@ -158,7 +158,7 @@
['startTest', 'addUnexpectedSuccess', 'stopTest'])
self.assertFalse(result.failures)
self.assertEqual(result.unexpectedSuccesses, [test])
- self.assertTrue(result.wasSuccessful())
+ self.assertFalse(result.wasSuccessful())
def test_unexpected_success_subtests(self):
# Success in all subtests counts as the unexpected success of
@@ -182,7 +182,7 @@
'addUnexpectedSuccess', 'stopTest'])
self.assertFalse(result.failures)
self.assertEqual(result.unexpectedSuccesses, [test])
- self.assertTrue(result.wasSuccessful())
+ self.assertFalse(result.wasSuccessful())
def test_skip_doesnt_run_setup(self):
class Foo(unittest.TestCase):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,9 @@
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
http.server.BaseHTTPRequestHandler. Patch by Nikolaus Rath.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list