https://github.com/python/cpython/commit/d85438045f6fce7579f964d82cf8529e338b9d82
commit: d85438045f6fce7579f964d82cf8529e338b9d82
branch: main
author: sendaoYan <[email protected]>
committer: orsenthil <[email protected]>
date: 2026-10-28T19:38:18Z
summary:

gh-148919: Make test_redirect_no_path independent of proxy environment 
variables (#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().

Co-Authored-By: Claude Opus 5.5 <[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]

Reply via email to