-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
21 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ class import_helper: # type: ignore | |
modules_setup, | ||
modules_cleanup, | ||
DirsOnSysPath, | ||
CleanImport, | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters