From 07d894d96777e77f9dac3ec671f2dce4c584a26d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 20 Mar 2024 13:49:52 -0400 Subject: [PATCH] Copy backport of isolated_modules from importlib_resources. --- tests/compat/py312.py | 18 ++++++++++++++++++ tests/compat/py39.py | 1 + 2 files changed, 19 insertions(+) create mode 100644 tests/compat/py312.py diff --git a/tests/compat/py312.py b/tests/compat/py312.py new file mode 100644 index 00000000..ea9a58ba --- /dev/null +++ b/tests/compat/py312.py @@ -0,0 +1,18 @@ +import contextlib + +from .py39 import import_helper + + +@contextlib.contextmanager +def isolated_modules(): + """ + Save modules on entry and cleanup on exit. + """ + (saved,) = import_helper.modules_setup() + try: + yield + finally: + import_helper.modules_cleanup(saved) + + +vars(import_helper).setdefault('isolated_modules', isolated_modules) diff --git a/tests/compat/py39.py b/tests/compat/py39.py index 0f6f9c3a..5fe61c39 100644 --- a/tests/compat/py39.py +++ b/tests/compat/py39.py @@ -4,3 +4,4 @@ os_helper = try_import('os_helper') or from_test_support( 'FS_NONASCII', 'skip_unless_symlink' ) +import_helper = try_import('import_helper') or from_test_support()