]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149977: Fix extra output of `-m test test_lazy_import` (#149978)
authorsobolevn <mail@sobolevn.me>
Mon, 18 May 2026 18:55:27 +0000 (21:55 +0300)
committerGitHub <noreply@github.com>
Mon, 18 May 2026 18:55:27 +0000 (21:55 +0300)
Lib/test/test_lazy_import/__init__.py

index 5d770eeae07a15f3b7f71e825ed851bceb2e1195..bcbf1a23233ba8d2fb4f96c321fa7e3c6fed7536 100644 (file)
@@ -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."""