mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-99645: Fix a bug in handling class cleanups in unittest.TestCase (GH-99646)
Now addClassCleanup() uses separate lists for different TestCase subclasses, and doClassCleanups() only cleans up the particular class.
This commit is contained in:
parent
d15b9f19ac
commit
c2102136be
3 changed files with 35 additions and 5 deletions
|
@ -547,6 +547,33 @@ class TestClassCleanup(unittest.TestCase):
|
|||
|
||||
self.assertEqual(TestableTest._class_cleanups, [])
|
||||
|
||||
def test_run_nested_test(self):
|
||||
ordering = []
|
||||
|
||||
class InnerTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
ordering.append('inner setup')
|
||||
cls.addClassCleanup(ordering.append, 'inner cleanup')
|
||||
def test(self):
|
||||
ordering.append('inner test')
|
||||
|
||||
class OuterTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
ordering.append('outer setup')
|
||||
cls.addClassCleanup(ordering.append, 'outer cleanup')
|
||||
def test(self):
|
||||
ordering.append('start outer test')
|
||||
runTests(InnerTest)
|
||||
ordering.append('end outer test')
|
||||
|
||||
runTests(OuterTest)
|
||||
self.assertEqual(ordering, [
|
||||
'outer setup', 'start outer test',
|
||||
'inner setup', 'inner test', 'inner cleanup',
|
||||
'end outer test', 'outer cleanup'])
|
||||
|
||||
|
||||
class TestModuleCleanUp(unittest.TestCase):
|
||||
def test_add_and_do_ModuleCleanup(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue