From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 18 May 2026 19:24:06 +0000 (+0200) Subject: [3.15] gh-149977: Fix extra output of `-m test test_lazy_import` (GH-149978) (#150016) X-Git-Tag: v3.15.0b2~132 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=84ea87cde0132ca59f0390031d17b1f867dba8e0;p=thirdparty%2FPython%2Fcpython.git [3.15] gh-149977: Fix extra output of `-m test test_lazy_import` (GH-149978) (#150016) gh-149977: Fix extra output of `-m test test_lazy_import` (GH-149978) (cherry picked from commit 6d5be4b1d6ca91a18e76ae8dad2c5e94837d6309) Co-authored-by: sobolevn --- diff --git a/Lib/test/test_lazy_import/__init__.py b/Lib/test/test_lazy_import/__init__.py index 5d770eeae07a..bcbf1a23233b 100644 --- a/Lib/test/test_lazy_import/__init__.py +++ b/Lib/test/test_lazy_import/__init__.py @@ -10,6 +10,7 @@ import types import unittest import tempfile import os +import contextlib from test import support from test.support.script_helper import assert_python_ok @@ -441,10 +442,14 @@ class PackageTests(unittest.TestCase): def test_lazy_import_pkg(self): """lazy import of package submodule should load the package.""" - import test.test_lazy_import.data.lazy_import_pkg + out = io.StringIO() + + with contextlib.redirect_stdout(out): + import test.test_lazy_import.data.lazy_import_pkg self.assertIn("test.test_lazy_import.data.pkg", sys.modules) self.assertIn("test.test_lazy_import.data.pkg.bar", sys.modules) + self.assertIn("BAR_MODULE_LOADED", out.getvalue()) def test_lazy_import_pkg_cross_import(self): """Cross-imports within package should preserve lazy imports."""