From 48bec69efdd33633f6d73b4977493275504cb1a4 Mon Sep 17 00:00:00 2001 From: lazerg Date: Thu, 24 Sep 2026 18:54:56 +0500 Subject: [PATCH 1/2] gh-158086: Fix unittest.main shadowed by its submodule under lazy imports --- Lib/test/lazy_imports_all_exclude.txt | 1 - Lib/unittest/__init__.py | 4 +++- .../Library/2026-09-24-13-54-51.gh-issue-158086.SYyFaV.rst | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-09-24-13-54-51.gh-issue-158086.SYyFaV.rst diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt index 2680d3b1e4357b7..3391726eacc0909 100644 --- a/Lib/test/lazy_imports_all_exclude.txt +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -37,4 +37,3 @@ test_symtable test_tools test_trace test_type_annotations -test_unittest diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index 78ff6bb4fdcce5d..ffe4e913bcad293 100644 --- a/Lib/unittest/__init__.py +++ b/Lib/unittest/__init__.py @@ -59,7 +59,9 @@ def testMultiply(self): enterModuleContext) from .suite import BaseTestSuite, TestSuite # noqa: F401 from .loader import TestLoader, defaultTestLoader -from .main import TestProgram, main # noqa: F401 +from .main import TestProgram +# A lazily imported 'main' would be rebound to the submodule once it loads. +main = TestProgram from .runner import TextTestRunner, TextTestResult from .signals import installHandler, registerResult, removeResult, removeHandler # IsolatedAsyncioTestCase will be imported lazily. diff --git a/Misc/NEWS.d/next/Library/2026-09-24-13-54-51.gh-issue-158086.SYyFaV.rst b/Misc/NEWS.d/next/Library/2026-09-24-13-54-51.gh-issue-158086.SYyFaV.rst new file mode 100644 index 000000000000000..202d5814c96410a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-09-24-13-54-51.gh-issue-158086.SYyFaV.rst @@ -0,0 +1,2 @@ +:func:`unittest.main` no longer resolves to the :mod:`!unittest.main` +submodule when lazy imports are enabled with ``-X lazy_imports=all``. From 4e7daae27ca1ca11ac07cb6304ba19137f8a617a Mon Sep 17 00:00:00 2001 From: lazerg Date: Thu, 24 Sep 2026 19:31:21 +0500 Subject: [PATCH 2/2] Remove test_pyrepl from the lazy imports exclude list --- Lib/test/lazy_imports_all_exclude.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt index 3391726eacc0909..75689f18f21be36 100644 --- a/Lib/test/lazy_imports_all_exclude.txt +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -31,7 +31,6 @@ test_json test_pkg test_profile test_profiling -test_pyrepl test_subprocess test_symtable test_tools