Visitar URL original
gh-102251: Updates to test_imp Toward Fixing Some Refleaks by ericsnowcurrently · Pull Request #102254 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Do the initial cleanup in setUpClass().
  • Loading branch information
ericsnowcurrently committed Feb 24, 2023
commit fc940603fc0b6cc6b0ccf05b4740f971b2df7f01
31 changes: 18 additions & 13 deletions Lib/test/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,19 +668,24 @@ def setUpClass(cls):
fileobj.close()
cls.FILE = filename

def setUp(self):
# Start and end fresh.
def clean_up():
name = self.NAME
if name in sys.modules:
if hasattr(sys.modules[name], '_clear_globals'):
assert sys.modules[name].__file__ == self.FILE
sys.modules[name]._clear_globals()
del sys.modules[name]
# Clear all internally cached data for the extension.
_testinternalcapi.clear_extension(name, self.FILE)
clean_up()
self.addCleanup(clean_up)
# Start fresh.
cls.clean_up()

def tearDown(self):
# Clean up the module.
self.clean_up()

@classmethod
def clean_up(cls):
name = cls.NAME
filename = cls.FILE
if name in sys.modules:
if hasattr(sys.modules[name], '_clear_globals'):
assert sys.modules[name].__file__ == filename
sys.modules[name]._clear_globals()
del sys.modules[name]
# Clear all internally cached data for the extension.
_testinternalcapi.clear_extension(name, filename)

#########################
# helpers
Expand Down