Skip to content

Commit 84ea87c

Browse files
[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 6d5be4b) Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 01b07df commit 84ea87c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/test/test_lazy_import/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import unittest
1111
import tempfile
1212
import os
13+
import contextlib
1314

1415
from test import support
1516
from test.support.script_helper import assert_python_ok
@@ -441,10 +442,14 @@ def tearDown(self):
441442

442443
def test_lazy_import_pkg(self):
443444
"""lazy import of package submodule should load the package."""
444-
import test.test_lazy_import.data.lazy_import_pkg
445+
out = io.StringIO()
446+
447+
with contextlib.redirect_stdout(out):
448+
import test.test_lazy_import.data.lazy_import_pkg
445449

446450
self.assertIn("test.test_lazy_import.data.pkg", sys.modules)
447451
self.assertIn("test.test_lazy_import.data.pkg.bar", sys.modules)
452+
self.assertIn("BAR_MODULE_LOADED", out.getvalue())
448453

449454
def test_lazy_import_pkg_cross_import(self):
450455
"""Cross-imports within package should preserve lazy imports."""

0 commit comments

Comments
 (0)