]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-149977: Fix extra output of `-m test test_lazy_import`, again (GH-150965...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 5 Jun 2026 15:46:57 +0000 (17:46 +0200)
committerGitHub <noreply@github.com>
Fri, 5 Jun 2026 15:46:57 +0000 (15:46 +0000)
gh-149977: Fix extra output of `-m test test_lazy_import`, again (GH-150965)
(cherry picked from commit 9b4090c48e0b5e51f15ca0c52f7c173de71e3ba6)

Co-authored-by: sobolevn <mail@sobolevn.me>
Lib/test/test_lazy_import/__init__.py

index 2a82ac78fb90fb8c60d549ab71bf40bb50a49f1a..aeb275b958ec5e6c12f4fd3f5592d5e28676f242 100644 (file)
@@ -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."""