]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-127591: Fix altering environment in test_urllib2 (unsetting no_proxy) ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 16 Apr 2025 11:06:53 +0000 (13:06 +0200)
committerGitHub <noreply@github.com>
Wed, 16 Apr 2025 11:06:53 +0000 (11:06 +0000)
(cherry picked from commit 8b7cb947c5046d8fb32aad532048de87e09ed3f9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_urllib2.py

index 229cb9d9741210cd542c2bea7b0a42e901c8c2f7..9ceba05a6e356a1cd469d2cd4ae3bb509d8bec49 100644 (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()