Skip to content

Commit 0f98488

Browse files
miss-islingtonsendaoYanorsenthilclaude
authored
[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 d854380) Co-authored-by: sendaoYan <yansendao@hygon.cn> Co-authored-by: Senthil Kumaran <senthil@python.org> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 84ce091 commit 0f98488

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎Lib/test/test_urllib2.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,8 +1436,15 @@ def test_redirect_fragment(self):
14361436
fp = o.open('http://www.example.com')
14371437
self.assertEqual(fp.geturl(), redirected_url.strip())
14381438

1439+
def unset_proxy_env(self):
1440+
# Keep the test independent from proxy-related environment settings.
1441+
env = self.enterContext(os_helper.EnvironmentVarGuard())
1442+
env.unset("http_proxy", "https_proxy", "all_proxy", "no_proxy",
1443+
"HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY")
1444+
14391445
def test_redirect_no_path(self):
14401446
# Issue 14132: Relative redirect strips original path
1447+
self.unset_proxy_env()
14411448

14421449
# clear _opener global variable
14431450
self.addCleanup(urllib.request.urlcleanup)
@@ -1471,6 +1478,7 @@ def http_open(self, req):
14711478
b'123'
14721479
)
14731480
return result
1481+
self.unset_proxy_env()
14741482
handler = Handler()
14751483
opener = urllib.request.build_opener(handler)
14761484
tests = (

0 commit comments

Comments
 (0)