Skip to content

Commit 8b7cb94

Browse files
gh-127591: Fix altering environment in test_urllib2 (unsetting no_proxy) (GH-132584)
1 parent 8cb177d commit 8b7cb94

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Lib/test/test_urllib2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,8 @@ def test_proxy(self):
14461446
[tup[0:2] for tup in o.calls])
14471447

14481448
def test_proxy_no_proxy(self):
1449-
os.environ['no_proxy'] = 'python.org'
1449+
env = self.enterContext(os_helper.EnvironmentVarGuard())
1450+
env['no_proxy'] = 'python.org'
14501451
o = OpenerDirector()
14511452
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
14521453
o.add_handler(ph)
@@ -1458,18 +1459,17 @@ def test_proxy_no_proxy(self):
14581459
self.assertEqual(req.host, "www.python.org")
14591460
o.open(req)
14601461
self.assertEqual(req.host, "www.python.org")
1461-
del os.environ['no_proxy']
14621462

14631463
def test_proxy_no_proxy_all(self):
1464-
os.environ['no_proxy'] = '*'
1464+
env = self.enterContext(os_helper.EnvironmentVarGuard())
1465+
env['no_proxy'] = '*'
14651466
o = OpenerDirector()
14661467
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
14671468
o.add_handler(ph)
14681469
req = Request("http://www.python.org")
14691470
self.assertEqual(req.host, "www.python.org")
14701471
o.open(req)
14711472
self.assertEqual(req.host, "www.python.org")
1472-
del os.environ['no_proxy']
14731473

14741474
def test_proxy_https(self):
14751475
o = OpenerDirector()

0 commit comments

Comments
 (0)