forked from lektor/lektor
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conftest.restore_import_state should restore sys.meta_path as well as…
… sys.path (lektor#1140) * test(conftest.restore_import_state): ensure sys.meta_path is restored * fix(conftest.restore_import_state): restore sys.meta_path * fix(test_pluginsystem): preserve sys.meta_path * refactor(conftest.restore_import_state): cleanup & paranoia * test(tests): check that tests do not alter sys.path * fix(tests): fix the tests that were munging sys.path
- Loading branch information
Showing
8 changed files
with
95 additions
and
27 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
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
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,39 @@ | ||
import sys | ||
from contextlib import suppress | ||
from importlib import import_module | ||
|
||
from lektor.compat import importlib_metadata | ||
|
||
# pylint: disable-next=wrong-import-order | ||
from conftest import restore_import_state # noreorder | ||
|
||
|
||
def test_restore_import_state_restores_meta_path(): | ||
# Various modules (e.g. setuptools, importlib_metadata), when imported, | ||
# add their own finders to sys.meta_path. | ||
meta_path = sys.meta_path.copy() | ||
|
||
with restore_import_state(), suppress(ModuleNotFoundError): | ||
import_module("importlib_metadata") | ||
|
||
assert sys.meta_path == meta_path | ||
|
||
|
||
def test_restore_import_state_restores_unneutered_PathFinder(): | ||
# When importlib_metadata is imported, it neuters the stdlib | ||
# distribution find, and then adds its own finder to meta_path. | ||
# | ||
# This tests that restore_import_state manages to unneuter | ||
# this find. | ||
distributions_pre = [ | ||
dist.metadata["name"] for dist in importlib_metadata.distributions() | ||
] | ||
|
||
with restore_import_state(), suppress(ModuleNotFoundError): | ||
import_module("importlib_metadata") | ||
|
||
distributions_post = [ | ||
dist.metadata["name"] for dist in importlib_metadata.distributions() | ||
] | ||
assert len(distributions_pre) == len(distributions_post) | ||
assert set(distributions_pre) == set(distributions_post) |
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
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
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
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
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