summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib2.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-07-02 12:50:19 (GMT)
committerGitHub <noreply@github.com>2019-07-02 12:50:19 (GMT)
commit7cb9204ee1cf204f6f507d99a60f7c5bb359eebb (patch)
treeae351690ede26e65b690c5802de6aa0a850894ee /Lib/test/test_urllib2.py
parent039fb49c185570ab7b02f13fbdc51c859cfd831e (diff)
downloadcpython-7cb9204ee1cf204f6f507d99a60f7c5bb359eebb.zip
cpython-7cb9204ee1cf204f6f507d99a60f7c5bb359eebb.tar.gz
cpython-7cb9204ee1cf204f6f507d99a60f7c5bb359eebb.tar.bz2
bpo-37421: urllib.request tests call urlcleanup() (GH-14529)
urllib.request tests now call urlcleanup() to remove temporary files created by urlretrieve() tests and to clear the _opener global variable set by urlopen() and functions calling indirectly urlopen(). regrtest now checks if urllib.request._url_tempfiles and urllib.request._opener are changed by tests.
Diffstat (limited to 'Lib/test/test_urllib2.py')
-rw-r--r--Lib/test/test_urllib2.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index c6d275e..debb3c2 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -47,6 +47,9 @@ class TrivialTests(unittest.TestCase):
def test_trivial(self):
# A couple trivial tests
+ # clear _opener global variable
+ self.addCleanup(urllib.request.urlcleanup)
+
self.assertRaises(ValueError, urllib.request.urlopen, 'bogus url')
# XXX Name hacking to get this to work on Windows.
@@ -1290,6 +1293,10 @@ class HandlerTests(unittest.TestCase):
def test_redirect_no_path(self):
# Issue 14132: Relative redirect strips original path
+
+ # clear _opener global variable
+ self.addCleanup(urllib.request.urlcleanup)
+
real_class = http.client.HTTPConnection
response1 = b"HTTP/1.1 302 Found\r\nLocation: ?query\r\n\r\n"
http.client.HTTPConnection = test_urllib.fakehttp(response1)