]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127591: Fix altering environment in test_urllib2 (unsetting no_proxy) (GH-132584)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 16 Apr 2025 10:05:54 +0000 (13:05 +0300)
committerGitHub <noreply@github.com>
Wed, 16 Apr 2025 10:05:54 +0000 (13:05 +0300)
Lib/test/test_urllib2.py

index b1229607c516c774c01e8a0f22a504358d9d5a6e..7d7f2fa00d35b62964b4648d1e63d6e2c7af0c38 100644 (file)
@@ -1446,7 +1446,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)
@@ -1458,10 +1459,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)
@@ -1469,7 +1470,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()