mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
test_import.test_module_with_large_stack(): unload the test module
Ensure that the module is unloaded to be able to run the test more than once, and to not leak memory.
This commit is contained in:
parent
7c679514a5
commit
ab5a58d827
1 changed files with 9 additions and 1 deletions
|
@ -149,16 +149,24 @@ class ImportTests(unittest.TestCase):
|
|||
sys.path.append('')
|
||||
importlib.invalidate_caches()
|
||||
|
||||
namespace = {}
|
||||
try:
|
||||
make_legacy_pyc(filename)
|
||||
# This used to crash.
|
||||
exec('import ' + module)
|
||||
exec('import ' + module, None, namespace)
|
||||
finally:
|
||||
# Cleanup.
|
||||
del sys.path[-1]
|
||||
unlink(filename + 'c')
|
||||
unlink(filename + 'o')
|
||||
|
||||
# Remove references to the module (unload the module)
|
||||
namespace.clear()
|
||||
try:
|
||||
del sys.modules[module]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def test_failing_import_sticks(self):
|
||||
source = TESTFN + ".py"
|
||||
with open(source, "w") as f:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue