https://github.com/python/cpython/commit/8128bcfa08c97e05362d463f446e524519db464c
commit: 8128bcfa08c97e05362d463f446e524519db464c
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-04-16T11:06:53Z
summary:

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

(cherry picked from commit 8b7cb947c5046d8fb32aad532048de87e09ed3f9)

Co-authored-by: Serhiy Storchaka <storch...@gmail.com>

files:
M Lib/test/test_urllib2.py

diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 229cb9d9741210..9ceba05a6e356a 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1432,7 +1432,8 @@ def test_proxy(self):
                              [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 @@ def test_proxy_no_proxy(self):
         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 @@ def test_proxy_no_proxy_all(self):
         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()

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to