gh-99645: Fix a bug in handling class cleanups in unittest.TestCase (… · python/cpython@c210213 · GitHub
Skip to content

Commit c210213

Browse files
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.
1 parent d15b9f1 commit c210213

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

Lib/test/test_unittest/test_runner.py

Lines changed: 27 additions & 0 deletions

Lib/unittest/case.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ class TestCase(object):
384384
# of difflib. See #11763.
385385
_diffThreshold = 2**16
386386

387-
# Attribute used by TestSuite for classSetUp
388-
389-
_classSetupFailed = False
390-
391-
_class_cleanups = []
387+
def __init_subclass__(cls, *args, **kwargs):
388+
# Attribute used by TestSuite for classSetUp
389+
cls._classSetupFailed = False
390+
cls._class_cleanups = []
391+
super().__init_subclass__(*args, **kwargs)
392392

393393
def __init__(self, methodName='runTest'):
394394
"""Create an instance of the class that will use the named test
Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)