File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1772,6 +1772,10 @@ Loading and running tests
17721772 Return ``True `` if all tests run so far have passed, otherwise returns
17731773 ``False ``.
17741774
1775+ .. versionchanged :: 3.4
1776+ Returns ``False `` if there were any :attr: `unexpectedSuccesses `
1777+ from tests marked with the :func: `expectedFailure ` decorator.
1778+
17751779
17761780 .. method :: stop()
17771781
Original file line number Diff line number Diff line change @@ -156,11 +156,16 @@ def addUnexpectedSuccess(self, test):
156156 self .unexpectedSuccesses .append (test )
157157
158158 def wasSuccessful (self ):
159- "Tells whether or not this result was a success"
160- return len (self .failures ) == len (self .errors ) == 0
159+ """Tells whether or not this result was a success."""
160+ # The hasattr check is for test_result's OldResult test. That
161+ # way this method works on objects that lack the attribute.
162+ # (where would such result intances come from? old stored pickles?)
163+ return ((len (self .failures ) == len (self .errors ) == 0 ) and
164+ (not hasattr (self , 'unexpectedSuccesses' ) or
165+ len (self .unexpectedSuccesses ) == 0 ))
161166
162167 def stop (self ):
163- "Indicates that the tests should be aborted"
168+ """ Indicates that the tests should be aborted."" "
164169 self .shouldStop = True
165170
166171 def _exc_info_to_string (self , err , test ):
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ def test_die(self):
158158 ['startTest' , 'addUnexpectedSuccess' , 'stopTest' ])
159159 self .assertFalse (result .failures )
160160 self .assertEqual (result .unexpectedSuccesses , [test ])
161- self .assertTrue (result .wasSuccessful ())
161+ self .assertFalse (result .wasSuccessful ())
162162
163163 def test_unexpected_success_subtests (self ):
164164 # Success in all subtests counts as the unexpected success of
@@ -182,7 +182,7 @@ def test_die(self):
182182 'addUnexpectedSuccess' , 'stopTest' ])
183183 self .assertFalse (result .failures )
184184 self .assertEqual (result .unexpectedSuccesses , [test ])
185- self .assertTrue (result .wasSuccessful ())
185+ self .assertFalse (result .wasSuccessful ())
186186
187187 def test_skip_doesnt_run_setup (self ):
188188 class Foo (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ Core and Builtins
2525Library
2626-------
2727
28+ - Issue #20165: The unittest module no longer considers tests marked with
29+ @expectedFailure successful if they pass.
30+
2831- Issue #18574: Added missing newline in 100-Continue reply from
2932 http.server.BaseHTTPRequestHandler. Patch by Nikolaus Rath.
3033
You can’t perform that action at this time.
0 commit comments