https://github.com/python/cpython/commit/0f984887170bae0a5ebb33c71fc060a4a542330f commit: 0f984887170bae0a5ebb33c71fc060a4a542330f branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: orsenthil <[email protected]> date: 2026-10-28T20:13:35Z summary:
[3.14] gh-148919: Make test_redirect_no_path independent of proxy environment variables (GH-148920) (#160847) gh-148919: Make test_redirect_no_path independent of proxy environment variables (GH-148920) 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 fd6b90ae2477d3..e1bfdc474751f1 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1436,8 +1436,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) @@ -1471,6 +1478,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]
