summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2014-01-20 09:11:18 (GMT)
committerGregory P. Smith <greg@krypto.org>2014-01-20 09:11:18 (GMT)
commit5a6d4bf671699152fb417e8f8ba899aa5e1d8d42 (patch)
tree584a650328b944fb631b8ad75129f42da1686b94 /Lib/unittest
parentb599c61179dcc675def318e093dae87a80e01c74 (diff)
downloadcpython-5a6d4bf671699152fb417e8f8ba899aa5e1d8d42.zip
cpython-5a6d4bf671699152fb417e8f8ba899aa5e1d8d42.tar.gz
cpython-5a6d4bf671699152fb417e8f8ba899aa5e1d8d42.tar.bz2
Fixes Issue #20165: The unittest module no longer considers tests marked with
@expectedFailure successful if they pass.
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/result.py11
-rw-r--r--Lib/unittest/test/test_skipping.py4
2 files changed, 10 insertions, 5 deletions
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
index f3f4b67..b967a60 100644
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -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):
diff --git a/Lib/unittest/test/test_skipping.py b/Lib/unittest/test/test_skipping.py
index e18caa4..314a7a4 100644
--- a/Lib/unittest/test/test_skipping.py
+++ b/Lib/unittest/test/test_skipping.py
@@ -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):