]> granicus.if.org Git - python/commitdiff
Fixes Issue #20165: The unittest module no longer considers tests marked with
authorGregory P. Smith <greg@krypto.org>
Mon, 20 Jan 2014 09:11:18 +0000 (01:11 -0800)
committerGregory P. Smith <greg@krypto.org>
Mon, 20 Jan 2014 09:11:18 +0000 (01:11 -0800)
@expectedFailure successful if they pass.

Doc/library/unittest.rst
Lib/unittest/result.py
Lib/unittest/test/test_skipping.py
Misc/NEWS

index 5cbc51b7fcb7bb6de9a0463cb8f429e8cd8944b7..537cc3b6d2e2532c0b0976d0d0e2fb5c688a6814 100644 (file)
@@ -1772,6 +1772,10 @@ Loading and running tests
       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()
 
index f3f4b676a30f157cd75aa027c99f43bf79256213..b967a60a01f7a9e3fabfe7816652a9fb1175fed4 100644 (file)
@@ -156,11 +156,16 @@ class TestResult(object):
         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):
index e18caa48ba4ddda2f1d8080b8344bdb76f5ae522..314a7a4d0f8738ce6c0447e4ca5b102a42cd4bd3 100644 (file)
@@ -158,7 +158,7 @@ class Test_TestSkipping(unittest.TestCase):
                          ['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 @@ class Test_TestSkipping(unittest.TestCase):
                           '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):
index faac326ed2aa9eb8adf619fda1541a1f87949ec7..19e2a6e9f1f40469b5ea0dd42ec7e3da48af8780 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,9 @@ Core and Builtins
 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.