Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will affect all instances of HTTPConnection.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fakehttp replaces http.client.HTTPConnection with FakeHTTPConnection and unfakehttp restores the old value of http.client.HTTPConnection at the end of test. So I guess it's changing close on FakeHTTPConnection which is generated per test.

https://github.com/python/cpython/pull/13317/files#diff-618652ed25a24a1b635417b4264c9533L101

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @tirkarthi is right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adding a close() method to FakeHTTPConnection?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no test case failures on changing close in FakeHTTPConnection but I haven't had time to analyze it well to see if there are any other cases it affects. So I kept the change minimal to have reported tests silenced.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I wrote a similar change, I now understand this change and I agree that it's correct. But the change is surprising :-) I wrote PR #13996 which adds a "mock_close" attribute to fake_http(): if mock_close is true, a close() method which does nothing is defined. IMHO it's less surprising, since it's more explicitly that only the mock is affected.

self.assertRaises(OSError, urlopen, "http://python.org/")
finally:
self.unfakehttp()
Expand All @@ -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/")
Expand All @@ -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:
Expand Down