[3.13] gh-127591: Fix altering environment in test_urllib2 (unsetting no_proxy) (GH-132584) (GH-132585)

(cherry picked from commit 8b7cb947c5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-04-16 13:06:53 +02:00 committed by GitHub
parent 08faa2aeac
commit 8128bcfa08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1432,7 +1432,8 @@ class HandlerTests(unittest.TestCase):
[tup[0:2] for tup in o.calls])
def test_proxy_no_proxy(self):
os.environ['no_proxy'] = 'python.org'
env = self.enterContext(os_helper.EnvironmentVarGuard())
env['no_proxy'] = 'python.org'
o = OpenerDirector()
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
o.add_handler(ph)
@ -1444,10 +1445,10 @@ class HandlerTests(unittest.TestCase):
self.assertEqual(req.host, "www.python.org")
o.open(req)
self.assertEqual(req.host, "www.python.org")
del os.environ['no_proxy']
def test_proxy_no_proxy_all(self):
os.environ['no_proxy'] = '*'
env = self.enterContext(os_helper.EnvironmentVarGuard())
env['no_proxy'] = '*'
o = OpenerDirector()
ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
o.add_handler(ph)
@ -1455,7 +1456,6 @@ class HandlerTests(unittest.TestCase):
self.assertEqual(req.host, "www.python.org")
o.open(req)
self.assertEqual(req.host, "www.python.org")
del os.environ['no_proxy']
def test_proxy_https(self):
o = OpenerDirector()