Skip to content

Commit fc94060

Browse files
Do the initial cleanup in setUpClass().
1 parent 993484e commit fc94060

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

Lib/test/test_imp.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -668,19 +668,24 @@ def setUpClass(cls):
668668
fileobj.close()
669669
cls.FILE = filename
670670

671-
def setUp(self):
672-
# Start and end fresh.
673-
def clean_up():
674-
name = self.NAME
675-
if name in sys.modules:
676-
if hasattr(sys.modules[name], '_clear_globals'):
677-
assert sys.modules[name].__file__ == self.FILE
678-
sys.modules[name]._clear_globals()
679-
del sys.modules[name]
680-
# Clear all internally cached data for the extension.
681-
_testinternalcapi.clear_extension(name, self.FILE)
682-
clean_up()
683-
self.addCleanup(clean_up)
671+
# Start fresh.
672+
cls.clean_up()
673+
674+
def tearDown(self):
675+
# Clean up the module.
676+
self.clean_up()
677+
678+
@classmethod
679+
def clean_up(cls):
680+
name = cls.NAME
681+
filename = cls.FILE
682+
if name in sys.modules:
683+
if hasattr(sys.modules[name], '_clear_globals'):
684+
assert sys.modules[name].__file__ == filename
685+
sys.modules[name]._clear_globals()
686+
del sys.modules[name]
687+
# Clear all internally cached data for the extension.
688+
_testinternalcapi.clear_extension(name, filename)
684689

685690
#########################
686691
# helpers

0 commit comments

Comments
 (0)