diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -275,17 +275,21 @@ Content-Type: text/html; charset=iso-885 self.assertTrue(e.exception.filename) self.assertTrue(e.exception.reason) def test_file_notexists(self): fd, tmp_file = tempfile.mkstemp() tmp_fileurl = 'file://' + tmp_file self.assertTrue(os.path.exists(tmp_file)) - self.assertTrue(urlopen(tmp_fileurl)) + tmp_url = urlopen(tmp_fileurl) + try: + self.assertTrue(tmp_url) + finally: + tmp_url.close() os.unlink(tmp_file) self.assertFalse(os.path.exists(tmp_file)) with self.assertRaises(urllib.error.URLError): urlopen(tmp_fileurl) def test_ftp_nohost(self): test_ftp_url = 'ftp:///path'