From ade6c645a838b1b9f83a1d32eea8a3c276443fc9 Mon Sep 17 00:00:00 2001 From: devdavidejesus Date: Fri, 23 Oct 2026 18:29:07 -0300 Subject: [PATCH] gh-160511: Ignore configured proxies in test_urllib.urlopen_HttpTests Two tests failed when https_proxy was set, because urlopen() then tunnels through the proxy and the invalid host is rejected later with ValueError (or URLError if the proxy is unreachable) instead of InvalidURL. Make getproxies() return no proxies in these tests and reset the cached opener. --- Lib/test/test_urllib.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index ab59727a8fd182..006bc4b39ae9c8 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -303,6 +303,14 @@ def test_getproxies_environment_prefer_lowercase(self): class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin): """Test urlopen() opening a fake http connection.""" + def setUp(self): + # Don't use proxies from the environment or the system settings, + # and don't reuse an opener created by an earlier test. + self.enterContext( + support.swap_attr(urllib.request, 'getproxies', lambda: {})) + urllib.request.urlcleanup() + self.addCleanup(urllib.request.urlcleanup) + def check_read(self, ver): self.fakehttp(b"HTTP/" + ver + b" 200 OK\r\n\r\nHello!") try: