From 510350e2c20ef350ab30f4f73829f9ca26bf77d6 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Tue, 14 May 2019 21:24:42 +0530 Subject: [PATCH 1/3] Don't close the object which is again closed by destructor --- Lib/test/test_urllib.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 7214492eca9d88..1351bb450e8a80 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -79,8 +79,6 @@ def readline(self, length=None): def close(self): self.io_refs -= 1 - if self.io_refs == 0: - io.BytesIO.close(self) class FakeHTTPConnection(http.client.HTTPConnection): From 064ec257b3c2475a15c921d99dbddcc1f68d2689 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Tue, 14 May 2019 21:42:05 +0530 Subject: [PATCH 2/3] Revert "Don't close the object which is again closed by destructor" This reverts commit 510350e2c20ef350ab30f4f73829f9ca26bf77d6. --- Lib/test/test_urllib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 1351bb450e8a80..7214492eca9d88 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -79,6 +79,8 @@ def readline(self, length=None): def close(self): self.io_refs -= 1 + if self.io_refs == 0: + io.BytesIO.close(self) class FakeHTTPConnection(http.client.HTTPConnection): From 134f2bef03b22f5a57bc235b6ab66f6b2e8a0510 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Tue, 14 May 2019 23:16:54 +0530 Subject: [PATCH 3/3] Mock close function to silence destructor errors --- Lib/test/test_urllib.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 7214492eca9d88..1ff6290c904210 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -402,6 +402,8 @@ def test_read_bogus(self): Content-Type: text/html; charset=iso-8859-1 ''') try: + # Silence destructor error + http.client.HTTPConnection.close = lambda self: None self.assertRaises(OSError, urlopen, "http://python.org/") finally: self.unfakehttp() @@ -416,6 +418,8 @@ def test_invalid_redirect(self): Content-Type: text/html; charset=iso-8859-1 ''') try: + # Silence destructor error + http.client.HTTPConnection.close = lambda self: None msg = "Redirection to url 'file:" with self.assertRaisesRegex(urllib.error.HTTPError, msg): urlopen("http://python.org/") @@ -431,6 +435,8 @@ def test_redirect_limit_independent(self): Connection: close ''') try: + # Silence destructor error + http.client.HTTPConnection.close = lambda self: None self.assertRaises(urllib.error.HTTPError, urlopen, "http://something") finally: