MCPcopy Index your code
hub / github.com/python/cpython / testCleanupInRun

Method testCleanupInRun

Lib/test/test_unittest/test_runner.py:142–186  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

140 self.assertIn(f'{CustomErrorRepr}: bar', msg2)
141
142 def testCleanupInRun(self):
143 blowUp = False
144 ordering = []
145
146 class TestableTest(unittest.TestCase):
147 def setUp(self):
148 ordering.append('setUp')
149 test.addCleanup(cleanup2)
150 if blowUp:
151 raise CustomError('foo')
152
153 def testNothing(self):
154 ordering.append('test')
155 test.addCleanup(cleanup3)
156
157 def tearDown(self):
158 ordering.append('tearDown')
159
160 test = TestableTest('testNothing')
161
162 def cleanup1():
163 ordering.append('cleanup1')
164 def cleanup2():
165 ordering.append('cleanup2')
166 def cleanup3():
167 ordering.append('cleanup3')
168 test.addCleanup(cleanup1)
169
170 def success(some_test):
171 self.assertEqual(some_test, test)
172 ordering.append('success')
173
174 result = unittest.TestResult()
175 result.addSuccess = success
176
177 test.run(result)
178 self.assertEqual(ordering, ['setUp', 'test', 'tearDown', 'cleanup3',
179 'cleanup2', 'cleanup1', 'success'])
180
181 blowUp = True
182 ordering = []
183 test = TestableTest('testNothing')
184 test.addCleanup(cleanup1)
185 test.run(result)
186 self.assertEqual(ordering, ['setUp', 'cleanup2', 'cleanup1'])
187
188 def testTestCaseDebugExecutesCleanups(self):
189 ordering = []

Callers

nothing calls this directly

Calls 4

addCleanupMethod · 0.80
TestableTestClass · 0.70
runMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected