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.
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 @@
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 @@
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)