mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-116307: Proper fix for 'mod' leaking across importlib tests (#116680)
gh-116307: Create a new import helper 'isolated modules' and use that instead of 'Clean Import' to ensure that tests from importlib_resources don't leave modules in sys.modules.
This commit is contained in:
parent
bb66600558
commit
a254807761
3 changed files with 16 additions and 1 deletions
|
@ -268,6 +268,18 @@ def modules_cleanup(oldmodules):
|
|||
sys.modules.update(oldmodules)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def isolated_modules():
|
||||
"""
|
||||
Save modules on entry and cleanup on exit.
|
||||
"""
|
||||
(saved,) = modules_setup()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
modules_cleanup(saved)
|
||||
|
||||
|
||||
def mock_register_at_fork(func):
|
||||
# bpo-30599: Mock os.register_at_fork() when importing the random module,
|
||||
# since this function doesn't allow to unregister callbacks and would leak
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue