8000 Copy backport of isolated_modules from importlib_resources. · python/importlib_metadata@07d894d · GitHub
[go: up one dir, main page]

Skip to content

Commit 07d894d

Browse files
committed
Copy backport of isolated_modules from importlib_resources.
1 parent e30a16d commit 07d894d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tests/compat/py312.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import contextlib
2+
3+
from .py39 import import_helper
4+
5+
6+
@contextlib.contextmanager
7+
def isolated_modules():
8+
"""
9+
Save modules on entry and cleanup on exit.
10+
"""
11+
(saved,) = import_helper.modules_setup()
12+
try:
13+
yield
14+
finally:
15+
import_helper.modules_cleanup(saved)
16+
17+
18+
vars(import_helper).setdefault('isolated_modules', isolated_modules)

tests/compat/py39.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
os_helper = try_import('os_helper') or from_test_support(
55
'FS_NONASCII', 'skip_unless_symlink'
66
)
7+
import_helper = try_import('import_helper') or from_test_support()

0 commit comments

Comments
 (0)
0