Skip to content

Commit

Permalink
Copy backport of isolated_modules from importlib_resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 20, 2024
1 parent e30a16d commit 07d894d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/compat/py312.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions tests/compat/py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 07d894d

Please sign in to comment.