https://github.com/python/cpython/commit/1509a8831d2e1577917e50c4d64c0309da9e7333 commit: 1509a8831d2e1577917e50c4d64c0309da9e7333 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: orsenthil <[email protected]> date: 2026-10-28T20:13:00Z summary:
[3.15] gh-148919: Make test_redirect_no_path independent of proxy environment variables (GH-148920) (#160846) gh-148919: Make test_redirect_no_path independent of proxy environment variables (GH-148920) * gh-148919: Make test_redirect_no_path independent of proxy environment variables * gh-148919: Also make test_redirect_encoding independent of proxy env test_redirect_encoding uses build_opener(), which installs the default ProxyHandler, so it failed the same way when http_proxy was set. Move the environment cleanup into a helper and use EnvironmentVarGuard.unset(). --------- (cherry picked from commit d85438045f6fce7579f964d82cf8529e338b9d82) Co-authored-by: sendaoYan <[email protected]> Co-authored-by: Senthil Kumaran <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> files: M Lib/test/test_urllib2.py diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 3e4fec6e3e8474..571c1b2a89342d 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1453,8 +1453,15 @@ def test_redirect_fragment(self): fp = o.open('http://www.example.com') self.assertEqual(fp.geturl(), redirected_url.strip()) + def unset_proxy_env(self): + # Keep the test independent from proxy-related environment settings. + env = self.enterContext(os_helper.EnvironmentVarGuard()) + env.unset("http_proxy", "https_proxy", "all_proxy", "no_proxy", + "HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY") + def test_redirect_no_path(self): # Issue 14132: Relative redirect strips original path + self.unset_proxy_env() # clear _opener global variable self.addCleanup(urllib.request.urlcleanup) @@ -1488,6 +1495,7 @@ def http_open(self, req): b'123' ) return result + self.unset_proxy_env() handler = Handler() opener = urllib.request.build_opener(handler) tests = ( _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
