mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Close #17731: Clean up properly in test_import
This commit is contained in:
parent
26dfaac9ac
commit
f1465f0535
1 changed files with 3 additions and 0 deletions
|
@ -43,6 +43,7 @@ def _ready_to_import(name=None, source=""):
|
||||||
# sets up a temporary directory and removes it
|
# sets up a temporary directory and removes it
|
||||||
# creates the module file
|
# creates the module file
|
||||||
# temporarily clears the module from sys.modules (if any)
|
# temporarily clears the module from sys.modules (if any)
|
||||||
|
# reverts or removes the module when cleaning up
|
||||||
name = name or "spam"
|
name = name or "spam"
|
||||||
with script_helper.temp_dir() as tempdir:
|
with script_helper.temp_dir() as tempdir:
|
||||||
path = script_helper.make_script(tempdir, name, source)
|
path = script_helper.make_script(tempdir, name, source)
|
||||||
|
@ -54,6 +55,8 @@ def _ready_to_import(name=None, source=""):
|
||||||
finally:
|
finally:
|
||||||
if old_module is not None:
|
if old_module is not None:
|
||||||
sys.modules[name] = old_module
|
sys.modules[name] = old_module
|
||||||
|
elif name in sys.modules:
|
||||||
|
del sys.modules[name]
|
||||||
|
|
||||||
|
|
||||||
class ImportTests(unittest.TestCase):
|
class ImportTests(unittest.TestCase):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue