Skip to content

Commit 52b542b

Browse files
sobolevnhugovk
authored andcommitted
[3.15] gh-161660: Fix test_json with PYTHON_LAZY_IMPORTS=all (GH-161866)
(cherry picked from commit b107dc2) Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 47bbbb8 commit 52b542b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎Lib/test/support/import_helper.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def multi_interp_extensions_check(enabled=True):
160160
def import_fresh_module(name, fresh=(), blocked=(), *,
161161
deprecated=False,
162162
usefrozen=False,
163+
eager_imports=True,
163164
):
164165
"""Import and return a module, deliberately bypassing sys.modules.
165166
@@ -191,7 +192,12 @@ def import_fresh_module(name, fresh=(), blocked=(), *,
191192
"""
192193
# NOTE: test_heapq, test_json and test_warnings include extra sanity checks
193194
# to make sure that this utility function is working as expected
194-
with _ignore_deprecated_imports(deprecated):
195+
eager_imports_context = (
196+
force_eager_imports
197+
if eager_imports
198+
else contextlib.nullcontext
199+
)
200+
with eager_imports_context(), _ignore_deprecated_imports(deprecated):
195201
# Keep track of modules saved for later restoration as well
196202
# as those which just need a blocking entry removed
197203
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)