summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/import_helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/support/import_helper.py')
-rw-r--r--Lib/test/support/import_helper.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/support/import_helper.py b/Lib/test/support/import_helper.py
index 3d804f2..29c6f53 100644
--- a/Lib/test/support/import_helper.py
+++ b/Lib/test/support/import_helper.py
@@ -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