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

Side by Side Diff: Lib/unittest/test/test_skipping.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 | « Lib/unittest/result.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 2
3 from .support import LoggingResult 3 from .support import LoggingResult
4 4
5 5
6 class Test_TestSkipping(unittest.TestCase): 6 class Test_TestSkipping(unittest.TestCase):
7 7
8 def test_skipping(self): 8 def test_skipping(self):
9 class Foo(unittest.TestCase): 9 class Foo(unittest.TestCase):
10 def test_skip_me(self): 10 def test_skip_me(self):
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 def test_die(self): 151 def test_die(self):
152 pass 152 pass
153 events = [] 153 events = []
154 result = LoggingResult(events) 154 result = LoggingResult(events)
155 test = Foo("test_die") 155 test = Foo("test_die")
156 test.run(result) 156 test.run(result)
157 self.assertEqual(events, 157 self.assertEqual(events,
158 ['startTest', 'addUnexpectedSuccess', 'stopTest']) 158 ['startTest', 'addUnexpectedSuccess', 'stopTest'])
159 self.assertFalse(result.failures) 159 self.assertFalse(result.failures)
160 self.assertEqual(result.unexpectedSuccesses, [test]) 160 self.assertEqual(result.unexpectedSuccesses, [test])
161 self.assertTrue(result.wasSuccessful()) 161 self.assertFalse(result.wasSuccessful())
162 162
163 def test_unexpected_success_subtests(self): 163 def test_unexpected_success_subtests(self):
164 # Success in all subtests counts as the unexpected success of 164 # Success in all subtests counts as the unexpected success of
165 # the whole test. 165 # the whole test.
166 class Foo(unittest.TestCase): 166 class Foo(unittest.TestCase):
167 @unittest.expectedFailure 167 @unittest.expectedFailure
168 def test_die(self): 168 def test_die(self):
169 with self.subTest(): 169 with self.subTest():
170 # This one succeeds 170 # This one succeeds
171 pass 171 pass
172 with self.subTest(): 172 with self.subTest():
173 # So does this one 173 # So does this one
174 pass 174 pass
175 events = [] 175 events = []
176 result = LoggingResult(events) 176 result = LoggingResult(events)
177 test = Foo("test_die") 177 test = Foo("test_die")
178 test.run(result) 178 test.run(result)
179 self.assertEqual(events, 179 self.assertEqual(events,
180 ['startTest', 180 ['startTest',
181 'addSubTestSuccess', 'addSubTestSuccess', 181 'addSubTestSuccess', 'addSubTestSuccess',
182 'addUnexpectedSuccess', 'stopTest']) 182 'addUnexpectedSuccess', 'stopTest'])
183 self.assertFalse(result.failures) 183 self.assertFalse(result.failures)
184 self.assertEqual(result.unexpectedSuccesses, [test]) 184 self.assertEqual(result.unexpectedSuccesses, [test])
185 self.assertTrue(result.wasSuccessful()) 185 self.assertFalse(result.wasSuccessful())
186 186
187 def test_skip_doesnt_run_setup(self): 187 def test_skip_doesnt_run_setup(self):
188 class Foo(unittest.TestCase): 188 class Foo(unittest.TestCase):
189 wasSetUp = False 189 wasSetUp = False
190 wasTornDown = False 190 wasTornDown = False
191 def setUp(self): 191 def setUp(self):
192 Foo.wasSetUp = True 192 Foo.wasSetUp = True
193 def tornDown(self): 193 def tornDown(self):
194 Foo.wasTornDown = True 194 Foo.wasTornDown = True
195 @unittest.skip('testing') 195 @unittest.skip('testing')
(...skipping 22 matching lines...) Expand all
218 218
219 result = unittest.TestResult() 219 result = unittest.TestResult()
220 test = Foo("test_1") 220 test = Foo("test_1")
221 suite = unittest.TestSuite([test]) 221 suite = unittest.TestSuite([test])
222 suite.run(result) 222 suite.run(result)
223 self.assertEqual(result.skipped, [(test, "testing")]) 223 self.assertEqual(result.skipped, [(test, "testing")])
224 224
225 225
226 if __name__ == "__main__": 226 if __name__ == "__main__":
227 unittest.main() 227 unittest.main()
OLDNEW
« no previous file with comments | « Lib/unittest/result.py ('k') | no next file » | no next file with comments »

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