[Python-checkins] bpo-41939: Fix test_site.test_license_exists_at_url() (GH-22559) (#22567)

Miss Skeleton (bot) webhook-mailer at python.org
Mon Oct 5 12:49:50 EDT 2020


https://github.com/python/cpython/commit/10b4136bfa5878c058753e1d1bd091e0f7e1ba40
commit: 10b4136bfa5878c058753e1d1bd091e0f7e1ba40
branch: 3.9
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-10-05T18:49:41+02:00
summary:

bpo-41939: Fix test_site.test_license_exists_at_url() (GH-22559) (#22567)

Call urllib.request.urlcleanup() to reset the global
urllib.request._opener.
(cherry picked from commit 1fce240d6c4b2b2cc17a86e88c65169e15b9feeb)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
A Misc/NEWS.d/next/Tests/2020-10-05-09-37-43.bpo-41939.P4OlbA.rst
M Lib/test/test_site.py

diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 923f35efe2ede..ece6a07280634 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -509,6 +509,8 @@ def test_license_exists_at_url(self):
         # string displayed by license in the absence of a LICENSE file.
         url = license._Printer__data.split()[1]
         req = urllib.request.Request(url, method='HEAD')
+        # Reset global urllib.request._opener
+        self.addCleanup(urllib.request.urlcleanup)
         try:
             with socket_helper.transient_internet(url):
                 with urllib.request.urlopen(req) as data:
diff --git a/Misc/NEWS.d/next/Tests/2020-10-05-09-37-43.bpo-41939.P4OlbA.rst b/Misc/NEWS.d/next/Tests/2020-10-05-09-37-43.bpo-41939.P4OlbA.rst
new file mode 100644
index 0000000000000..e58ad2616da1b
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-10-05-09-37-43.bpo-41939.P4OlbA.rst
@@ -0,0 +1,3 @@
+Fix test_site.test_license_exists_at_url(): call
+``urllib.request.urlcleanup()`` to reset the global
+``urllib.request._opener``. Patch by Victor Stinner.



More information about the Python-checkins mailing list