diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt index 2680d3b1e4357b7..75689f18f21be36 100644 --- a/Lib/test/lazy_imports_all_exclude.txt +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -31,10 +31,8 @@ test_json test_pkg test_profile test_profiling -test_pyrepl test_subprocess 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``.