Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-99645: Fix a bug in handling class cleanups in unittest.TestCase#99646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletionsLib/test/test_unittest/test_runner.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -536,6 +536,33 @@ def testNothing(self):

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):
Expand Down
10 changes: 5 additions & 5 deletionsLib/unittest/case.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -384,11 +384,11 @@ class TestCase(object):
# of difflib. See #11763.
_diffThreshold = 2**16

# Attribute used by TestSuite for classSetUp

_classSetupFailed = False

_class_cleanups = []
def __init_subclass__(cls, *args, **kwargs):
# Attribute used by TestSuite for classSetUp
cls._classSetupFailed = False
cls._class_cleanups = []
super().__init_subclass__(*args, **kwargs)

def __init__(self, methodName='runTest'):
"""Create an instance of the class that will use the named test
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Fix a bug in handling class cleanups in :class:`unittest.TestCase`. Now
``addClassCleanup()`` uses separate lists for different ``TestCase``
subclasses, and ``doClassCleanups()`` only cleans up the particular class.

[8]ページ先頭

©2009-2025 Movatter.jp