New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_urllib fails in refleak mode #57132
Comments
Hi, test_urllib fails in refleak mode: ./python -m test -uall -v -R : test_urllib ====================================================================== Traceback (most recent call last):
File "/home/stefan/hg/cpython/Lib/test/test_urllib.py", line 235, in test_invalid_redirect
"http://python.org/")
AssertionError: HTTPError not raised by urlopen Ran 58 tests in 0.075s FAILED (failures=1, skipped=1) |
This appears to fail every 9th, 19th, 29th, etc. repetition of the test. This seems to be something to do with the reference counting/close logic of the FakeSocket but I haven't managed to figure out what. |
The actual problem is that FancyURLOpener self.tries isn't being reset if the protocol is file:// I've attached a patch that'll help improve the test at least. |
Here's a path to fix the problem. |
I just noticed this problem as well. I don't know the code well enough to determine if Brian's patch is the I see why this is a problem with our test code. 'Lib/test/test_urllib.py' _urlopener = None
def urlopen(url, data=None, proxies=None):
"""urlopen(url [, data]) -> open file-like object"""
global _urlopener
if proxies is not None:
opener = urllib.request.FancyURLopener(proxies=proxies)
elif not _urlopener:
opener = urllib.request.FancyURLopener()
_urlopener = opener
else:
opener = _urlopener
if data is None:
return opener.open(url)
else:
return opener.open(url, data) Notice that the 'FancyURLopener' instance is cached in a global variable. Senthil, can you chime in? |
Hi, Here is an alternate patch to the test suite that demonstrates the Thanks, |
All three patches look generally good to me. I left some comments on things I would change. FTR the tests fail to raise any exception when the redirect limit is reached because FancyURLopener.http_error_default() does not raise an error. It just returns the last result as a synthesized error page. |
I guess this is a real bug so should also be applied to Python 2. This patch combines the previous three, and tweaks a couple things:
|
New changeset eb69070e5382 by Martin Panter in branch '3.5': New changeset a8aa7944c5a8 by Martin Panter in branch '2.7': New changeset d3be5c4507b4 by Martin Panter in branch 'default': |
One extra change I made to test_redirect_limit_independent() was to stop relying on _urlopener being created before we call urlopen(). As a consequence, in the Python 3 tests I made a wrapper around FancyURLopener to suppress the deprecation warning. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: