From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 5 Jun 2026 15:46:57 +0000 (+0200) Subject: [3.15] gh-149977: Fix extra output of `-m test test_lazy_import`, again (GH-150965... X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=d0a263d6d6c94272249d76e139ce80f749103bfe;p=thirdparty%2FPython%2Fcpython.git [3.15] gh-149977: Fix extra output of `-m test test_lazy_import`, again (GH-150965) (#150975) gh-149977: Fix extra output of `-m test test_lazy_import`, again (GH-150965) (cherry picked from commit 9b4090c48e0b5e51f15ca0c52f7c173de71e3ba6) Co-authored-by: sobolevn --- diff --git a/Lib/test/test_lazy_import/__init__.py b/Lib/test/test_lazy_import/__init__.py index 2a82ac78fb90..aeb275b958ec 100644 --- a/Lib/test/test_lazy_import/__init__.py +++ b/Lib/test/test_lazy_import/__init__.py @@ -447,11 +447,15 @@ class PackageTests(LazyImportTestCase): def test_lazy_submodule_stored_in_parent_dict(self): """Accessing a lazy submodule should store it in the parent's __dict__.""" - 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 pkg = sys.modules["test.test_lazy_import.data.pkg"] self.assertIn("bar", pkg.__dict__) self.assertIs(pkg.__dict__["bar"], sys.modules["test.test_lazy_import.data.pkg.bar"]) + self.assertIn("BAR_MODULE_LOADED", out.getvalue()) def test_lazy_import_pkg_cross_import(self): """Cross-imports within package should preserve lazy imports."""