Skip to content

Commit d854380

Browse files
sendaoYanorsenthilclaude
authored
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 <noreply@anthropic.com> --------- Co-authored-by: Senthil Kumaran <senthil@python.org> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent af44688 commit d854380

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
@@ -1453,8 +1453,15 @@ def test_redirect_fragment(self):
14531453
fp = o.open('http://www.example.com')
14541454
self.assertEqual(fp.geturl(), redirected_url.strip())
14551455

1456+
def unset_proxy_env(self):
1457+
# Keep the test independent from proxy-related environment settings.
1458+
env = self.enterContext(os_helper.EnvironmentVarGuard())
1459+
env.unset("http_proxy", "https_proxy", "all_proxy", "no_proxy",
1460+
"HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY")
1461+
14561462
def test_redirect_no_path(self):
14571463
# Issue 14132: Relative redirect strips original path
1464+
self.unset_proxy_env()
14581465

14591466
# clear _opener global variable
14601467
self.addCleanup(urllib.request.urlcleanup)
@@ -1488,6 +1495,7 @@ def http_open(self, req):
14881495
b'123'
14891496
)
14901497
return result
1498+
self.unset_proxy_env()
14911499
handler = Handler()
14921500
opener = urllib.request.build_opener(handler)
14931501
tests = (

0 commit comments

Comments
 (0)