summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unittest/test_runner.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-11-21 11:57:30 (GMT)
committerGitHub <noreply@github.com>2022-11-21 11:57:30 (GMT)
commit653e563d80fabee8830e0b55f194f82a9beabe70 (patch)
tree6ccb646054de3a741a6562d5b96a6dfa28d9d349 /Lib/test/test_unittest/test_runner.py
parentcb2ef8b2acbb231c207207d3375b2f8b0077a6ee (diff)
downloadcpython-653e563d80fabee8830e0b55f194f82a9beabe70.zip
cpython-653e563d80fabee8830e0b55f194f82a9beabe70.tar.gz
cpython-653e563d80fabee8830e0b55f194f82a9beabe70.tar.bz2
Add more details in test_unittest (GH-99626)
Diffstat (limited to 'Lib/test/test_unittest/test_runner.py')
-rw-r--r--Lib/test/test_unittest/test_runner.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/Lib/test/test_unittest/test_runner.py b/Lib/test/test_unittest/test_runner.py
index d396f2b..569b265 100644
--- a/Lib/test/test_unittest/test_runner.py
+++ b/Lib/test/test_unittest/test_runner.py
@@ -134,11 +134,13 @@ class TestCleanUp(unittest.TestCase):
class TestableTest(unittest.TestCase):
def setUp(self):
ordering.append('setUp')
+ test.addCleanup(cleanup2)
if blowUp:
raise Exception('foo')
def testNothing(self):
ordering.append('test')
+ test.addCleanup(cleanup3)
def tearDown(self):
ordering.append('tearDown')
@@ -149,8 +151,9 @@ class TestCleanUp(unittest.TestCase):
ordering.append('cleanup1')
def cleanup2():
ordering.append('cleanup2')
+ def cleanup3():
+ ordering.append('cleanup3')
test.addCleanup(cleanup1)
- test.addCleanup(cleanup2)
def success(some_test):
self.assertEqual(some_test, test)
@@ -160,7 +163,7 @@ class TestCleanUp(unittest.TestCase):
result.addSuccess = success
test.run(result)
- self.assertEqual(ordering, ['setUp', 'test', 'tearDown',
+ self.assertEqual(ordering, ['setUp', 'test', 'tearDown', 'cleanup3',
'cleanup2', 'cleanup1', 'success'])
blowUp = True
@@ -168,7 +171,7 @@ class TestCleanUp(unittest.TestCase):
test = TestableTest('testNothing')
test.addCleanup(cleanup1)
test.run(result)
- self.assertEqual(ordering, ['setUp', 'cleanup1'])
+ self.assertEqual(ordering, ['setUp', 'cleanup2', 'cleanup1'])
def testTestCaseDebugExecutesCleanups(self):
ordering = []
@@ -180,9 +183,11 @@ class TestCleanUp(unittest.TestCase):
def testNothing(self):
ordering.append('test')
+ self.addCleanup(cleanup3)
def tearDown(self):
ordering.append('tearDown')
+ test.addCleanup(cleanup4)
test = TestableTest('testNothing')
@@ -191,9 +196,14 @@ class TestCleanUp(unittest.TestCase):
test.addCleanup(cleanup2)
def cleanup2():
ordering.append('cleanup2')
+ def cleanup3():
+ ordering.append('cleanup3')
+ def cleanup4():
+ ordering.append('cleanup4')
test.debug()
- self.assertEqual(ordering, ['setUp', 'test', 'tearDown', 'cleanup1', 'cleanup2'])
+ self.assertEqual(ordering, ['setUp', 'test', 'tearDown', 'cleanup4',
+ 'cleanup3', 'cleanup1', 'cleanup2'])
def test_enterContext(self):
@@ -352,13 +362,14 @@ class TestClassCleanup(unittest.TestCase):
ordering.append('test')
@classmethod
def tearDownClass(cls):
+ ordering.append('tearDownClass')
raise Exception('TearDownClassExc')
suite = unittest.defaultTestLoader.loadTestsFromTestCase(TestableTest)
with self.assertRaises(Exception) as cm:
suite.debug()
self.assertEqual(str(cm.exception), 'TearDownClassExc')
- self.assertEqual(ordering, ['setUpClass', 'test'])
+ self.assertEqual(ordering, ['setUpClass', 'test', 'tearDownClass'])
self.assertTrue(TestableTest._class_cleanups)
TestableTest._class_cleanups.clear()
@@ -368,7 +379,7 @@ class TestClassCleanup(unittest.TestCase):
with self.assertRaises(Exception) as cm:
suite.debug()
self.assertEqual(str(cm.exception), 'TearDownClassExc')
- self.assertEqual(ordering, ['setUpClass', 'test'])
+ self.assertEqual(ordering, ['setUpClass', 'test', 'tearDownClass'])
self.assertTrue(TestableTest._class_cleanups)
TestableTest._class_cleanups.clear()
@@ -747,6 +758,7 @@ class TestModuleCleanUp(unittest.TestCase):
unittest.addModuleCleanup(cleanup, ordering)
@staticmethod
def tearDownModule():
+ ordering.append('tearDownModule')
raise Exception('CleanUpExc')
class TestableTest(unittest.TestCase):
@@ -765,7 +777,8 @@ class TestModuleCleanUp(unittest.TestCase):
self.assertEqual(result.errors[0][1].splitlines()[-1],
'Exception: CleanUpExc')
self.assertEqual(ordering, ['setUpModule', 'setUpClass', 'test',
- 'tearDownClass', 'cleanup_good'])
+ 'tearDownClass', 'tearDownModule',
+ 'cleanup_good'])
self.assertEqual(unittest.case._module_cleanups, [])
def test_debug_module_executes_cleanUp(self):
@@ -819,6 +832,7 @@ class TestModuleCleanUp(unittest.TestCase):
unittest.addModuleCleanup(cleanup, ordering, blowUp=blowUp)
@staticmethod
def tearDownModule():
+ ordering.append('tearDownModule')
raise Exception('TearDownModuleExc')
class TestableTest(unittest.TestCase):
@@ -838,7 +852,7 @@ class TestModuleCleanUp(unittest.TestCase):
suite.debug()
self.assertEqual(str(cm.exception), 'TearDownModuleExc')
self.assertEqual(ordering, ['setUpModule', 'setUpClass', 'test',
- 'tearDownClass'])
+ 'tearDownClass', 'tearDownModule'])
self.assertTrue(unittest.case._module_cleanups)
unittest.case._module_cleanups.clear()
@@ -849,7 +863,7 @@ class TestModuleCleanUp(unittest.TestCase):
suite.debug()
self.assertEqual(str(cm.exception), 'TearDownModuleExc')
self.assertEqual(ordering, ['setUpModule', 'setUpClass', 'test',
- 'tearDownClass'])
+ 'tearDownClass', 'tearDownModule'])
self.assertTrue(unittest.case._module_cleanups)
unittest.case._module_cleanups.clear()