diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt index e5519323e88e38..f85ea5e4f301c0 100644 --- a/Lib/test/lazy_imports_all_exclude.txt +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -20,10 +20,8 @@ test.test_inspect.test_inspect test___all__ test__interpreters test_crossinterp -test_datetime test_import test_importlib -test_json test_pkg test_profile test_profiling diff --git a/Lib/test/support/import_helper.py b/Lib/test/support/import_helper.py index 962f65d8dcd14a..26790c6995e781 100644 --- a/Lib/test/support/import_helper.py +++ b/Lib/test/support/import_helper.py @@ -156,6 +156,7 @@ def multi_interp_extensions_check(enabled=True): def import_fresh_module(name, fresh=(), blocked=(), *, deprecated=False, usefrozen=False, + eager_imports=True, ): """Import and return a module, deliberately bypassing sys.modules. @@ -187,7 +188,12 @@ def import_fresh_module(name, fresh=(), blocked=(), *, """ # NOTE: test_heapq, test_json and test_warnings include extra sanity checks # to make sure that this utility function is working as expected - with _ignore_deprecated_imports(deprecated): + eager_imports_context = ( + force_eager_imports + if eager_imports + else contextlib.nullcontext + ) + with eager_imports_context(), _ignore_deprecated_imports(deprecated): # Keep track of modules saved for later restoration as well # as those which just need a blocking entry removed fresh = list(fresh) diff --git a/Lib/test/test_type_annotations.py b/Lib/test/test_type_annotations.py index 879a571d06b4a0..02f3e8b9caddb4 100644 --- a/Lib/test/test_type_annotations.py +++ b/Lib/test/test_type_annotations.py @@ -153,7 +153,11 @@ class D(metaclass=C): self.assertEqual(D.__annotations__, {}) def test_partially_executed_module(self): - partialexe = import_helper.import_fresh_module("test.typinganndata.partialexecution") + # Results are different with and without lazy imports, we need both: + partialexe = import_helper.import_fresh_module( + "test.typinganndata.partialexecution", + eager_imports=False, + ) self.assertEqual( partialexe.a.__annotations__, {"v1": int, "v2": int},