Skip to content

Commit 1406c72

Browse files
serhiy-storchakamiss-islington
authored andcommitted
pythongh-127591: Fix altering environment in test_urllib2 (unsetting no_proxy) (pythonGH-132584)
(cherry picked from commit 8b7cb94) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 08faa2a commit 1406c72

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
@@ -1432,7 +1432,8 @@ def test_proxy(self):
14321432
[tup[0:2] for tup in o.calls])
14331433

14341434
def test_proxy_no_proxy(self):
1435-
os.environ['no_proxy'] = 'python.org'
1435+
env = self.enterContext(os_helper.EnvironmentVarGuard())
1436+
env['no_proxy'] = 'python.org'
14361437
o = OpenerDirector()
14371438
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
14381439
o.add_handler(ph)
@@ -1444,18 +1445,17 @@ def test_proxy_no_proxy(self):
14441445
self.assertEqual(req.host, "www.python.org")
14451446
o.open(req)
14461447
self.assertEqual(req.host, "www.python.org")
1447-
del os.environ['no_proxy']
14481448

14491449
def test_proxy_no_proxy_all(self):
1450-
os.environ['no_proxy'] = '*'
1450+
env = self.enterContext(os_helper.EnvironmentVarGuard())
1451+
env['no_proxy'] = '*'
14511452
o = OpenerDirector()
14521453
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
14531454
o.add_handler(ph)
14541455
req = Request("http://www.python.org")
14551456
self.assertEqual(req.host, "www.python.org")
14561457
o.open(req)
14571458
self.assertEqual(req.host, "www.python.org")
1458-
del os.environ['no_proxy']
14591459

14601460
def test_proxy_https(self):
14611461
o = OpenerDirector()

0 commit comments

Comments
 (0)