From 697a659ea5af29a06f1d9da8e4d468dcf7887a2b Mon Sep 17 00:00:00 2001 From: ayaangazali Date: Tue, 18 Aug 2026 17:02:49 -0700 Subject: [PATCH 1/3] gh-156031: Restore urllib.request._opener in test_httpservers CommandLineRunTimeTestCase.fetch_file() calls urlopen() without an SSL context for the plain HTTP cases. urlopen() only builds a throwaway opener when a context is passed, so those calls install the urllib.request._opener module global and leave it set for the rest of the test run. test_urllib already guards the same global with addCleanup(urlcleanup) in several places; do the same here. --- Lib/test/test_httpservers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index 63f65a9c5cf47a..6f80968d575b07 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -1684,6 +1684,9 @@ class CommandLineRunTimeTestCase(unittest.TestCase): def setUp(self): super().setUp() + # fetch_file() calls urlopen() without an SSL context for the plain + # HTTP cases, which installs a process-wide default opener. + self.addCleanup(urllib.request.urlcleanup) server_dir_context = os_helper.temp_cwd() server_dir = self.enterContext(server_dir_context) with open(self.served_filename, 'wb') as f: From 5338d182c5841be2211453c62646175a8fe3a660 Mon Sep 17 00:00:00 2001 From: ayaangazali Date: Tue, 18 Aug 2026 17:10:25 -0700 Subject: [PATCH 2/3] gh-156031: Add NEWS entry --- .../next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst diff --git a/Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst b/Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst new file mode 100644 index 00000000000000..cd0c76ef7fea7b --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst @@ -0,0 +1,4 @@ +``test_httpservers`` no longer leaves a default opener installed in +:mod:`urllib.request`. The plain HTTP cases fetched URLs through +:func:`urllib.request.urlopen` without an SSL context, which sets the module +global, so the rest of the test run saw it instead of a fresh opener. From 0df1558689ed8c577b78c053ddecdc23843f0652 Mon Sep 17 00:00:00 2001 From: ayaangazali Date: Wed, 19 Aug 2026 16:18:53 -0700 Subject: [PATCH 3/3] Remove NEWS entry, test-only change --- .../next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst diff --git a/Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst b/Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst deleted file mode 100644 index cd0c76ef7fea7b..00000000000000 --- a/Misc/NEWS.d/next/Tests/2026-08-18-23-58-02.gh-issue-156031.Qm4TbX.rst +++ /dev/null @@ -1,4 +0,0 @@ -``test_httpservers`` no longer leaves a default opener installed in -:mod:`urllib.request`. The plain HTTP cases fetched URLs through -:func:`urllib.request.urlopen` without an SSL context, which sets the module -global, so the rest of the test run saw it instead of a fresh opener.