Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: Lib/unittest/result.py

Issue 20165: unittest TestResult wasSuccessful returns True when there are unexpected successes
Patch Set: Created 6 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/unittest/test/test_skipping.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Test result object""" 1 """Test result object"""
2 2
3 import io 3 import io
4 import sys 4 import sys
5 import traceback 5 import traceback
6 6
7 from . import util 7 from . import util
8 from functools import wraps 8 from functools import wraps
9 9
10 __unittest = True 10 __unittest = True
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 """Called when an expected failure/error occured.""" 149 """Called when an expected failure/error occured."""
150 self.expectedFailures.append( 150 self.expectedFailures.append(
151 (test, self._exc_info_to_string(err, test))) 151 (test, self._exc_info_to_string(err, test)))
152 152
153 @failfast 153 @failfast
154 def addUnexpectedSuccess(self, test): 154 def addUnexpectedSuccess(self, test):
155 """Called when a test was expected to fail, but succeed.""" 155 """Called when a test was expected to fail, but succeed."""
156 self.unexpectedSuccesses.append(test) 156 self.unexpectedSuccesses.append(test)
157 157
158 def wasSuccessful(self): 158 def wasSuccessful(self):
159 "Tells whether or not this result was a success" 159 """Tells whether or not this result was a success."""
160 return len(self.failures) == len(self.errors) == 0 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))
161 166
162 def stop(self): 167 def stop(self):
163 "Indicates that the tests should be aborted" 168 """Indicates that the tests should be aborted."""
164 self.shouldStop = True 169 self.shouldStop = True
165 170
166 def _exc_info_to_string(self, err, test): 171 def _exc_info_to_string(self, err, test):
167 """Converts a sys.exc_info()-style tuple of values into a string.""" 172 """Converts a sys.exc_info()-style tuple of values into a string."""
168 exctype, value, tb = err 173 exctype, value, tb = err
169 # Skip test runner traceback levels 174 # Skip test runner traceback levels
170 while tb and self._is_relevant_tb_level(tb): 175 while tb and self._is_relevant_tb_level(tb):
171 tb = tb.tb_next 176 tb = tb.tb_next
172 177
173 if exctype is test.failureException: 178 if exctype is test.failureException:
(...skipping 24 matching lines...) Expand all
198 length = 0 203 length = 0
199 while tb and not self._is_relevant_tb_level(tb): 204 while tb and not self._is_relevant_tb_level(tb):
200 length += 1 205 length += 1
201 tb = tb.tb_next 206 tb = tb.tb_next
202 return length 207 return length
203 208
204 def __repr__(self): 209 def __repr__(self):
205 return ("<%s run=%i errors=%i failures=%i>" % 210 return ("<%s run=%i errors=%i failures=%i>" %
206 (util.strclass(self.__class__), self.testsRun, len(self.errors), 211 (util.strclass(self.__class__), self.testsRun, len(self.errors),
207 len(self.failures))) 212 len(self.failures)))
OLDNEW
« no previous file with comments | « no previous file | Lib/unittest/test/test_skipping.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+