Skip to content

Commit b107dc2

Browse files
authored
gh-161660: Fix test_json with PYTHON_LAZY_IMPORTS=all (#161866)
1 parent aa17c68 commit b107dc2

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎Lib/test/lazy_imports_all_exclude.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ test.test_inspect.test_inspect
2020
test___all__
2121
test__interpreters
2222
test_crossinterp
23-
test_datetime
2423
test_import
2524
test_importlib
26-
test_json
2725
test_pkg
2826
test_profile
2927
test_profiling

‎Lib/test/support/import_helper.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def multi_interp_extensions_check(enabled=True):
156156
def import_fresh_module(name, fresh=(), blocked=(), *,
157157
deprecated=False,
158158
usefrozen=False,
159+
eager_imports=True,
159160
):
160161
"""Import and return a module, deliberately bypassing sys.modules.
161162
@@ -187,7 +188,12 @@ def import_fresh_module(name, fresh=(), blocked=(), *,
187188
"""
188189
# NOTE: test_heapq, test_json and test_warnings include extra sanity checks
189190
# to make sure that this utility function is working as expected
190-
with _ignore_deprecated_imports(deprecated):
191+
eager_imports_context = (
192+
force_eager_imports
193+
if eager_imports
194+
else contextlib.nullcontext
195+
)
196+
with eager_imports_context(), _ignore_deprecated_imports(deprecated):
191197
# Keep track of modules saved for later restoration as well
192198
# as those which just need a blocking entry removed
193199
fresh = list(fresh)

‎Lib/test/test_type_annotations.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ class D(metaclass=C):
153153
self.assertEqual(D.__annotations__, {})
154154

155155
def test_partially_executed_module(self):
156-
partialexe = import_helper.import_fresh_module("test.typinganndata.partialexecution")
156+
# Results are different with and without lazy imports, we need both:
157+
partialexe = import_helper.import_fresh_module(
158+
"test.typinganndata.partialexecution",
159+
eager_imports=False,
160+
)
157161
self.assertEqual(
158162
partialexe.a.__annotations__,
159163
{"v1": int, "v2": int},

0 commit comments

Comments
 (0)