diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-11-22 17:11:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 17:11:57 (GMT) |
commit | 400d41b8ea73e71ca583daca94da3db06417f210 (patch) | |
tree | 526b11eefc02dfb811a4e64026c084a9823db180 /Lib/unittest/test | |
parent | 190331ed280ba292dc3d0419f65ed2ecf12aa06e (diff) | |
download | cpython-400d41b8ea73e71ca583daca94da3db06417f210.zip cpython-400d41b8ea73e71ca583daca94da3db06417f210.tar.gz cpython-400d41b8ea73e71ca583daca94da3db06417f210.tar.bz2 |
[3.10] gh-99645: Fix a bug in handling class cleanups in unittest.TestCase (GH-99646) (GH-99699)
Now addClassCleanup() uses separate lists for different TestCase subclasses,
and doClassCleanups() only cleans up the particular class.
(cherry picked from commit c2102136be569e6fc8ed90181f229b46d07142f8)
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_runner.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_runner.py b/Lib/unittest/test/test_runner.py index 613ff5b..0082d39 100644 --- a/Lib/unittest/test/test_runner.py +++ b/Lib/unittest/test/test_runner.py @@ -457,6 +457,33 @@ class TestClassCleanup(unittest.TestCase): self.assertEqual(ordering, ['setUpClass', 'test', 'tearDownClass', 'cleanup_good']) + 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): |