classification
Title: test_missing_localfile masks problems in urlopen
Type: behavior Stage: resolved
Components: Tests Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: HansM, orsenthil, python-dev
Priority: normal Keywords:

Created on 2012-11-10 14:42 by HansM, last changed 2013-06-01 15:03 by orsenthil. This issue is now closed.

Messages (3)
msg175278 - (view) Author: Hans Mulder (HansM) Date: 2012-11-10 14:42
Due to a misconfiguration, urllib.thishost() raises an IOError
on my laptop.  This causes urllib.urlopen to raise an exception.
A flaw in test_missing_localfile causes this exception to not be
reported.  The problem happens at line 230-235:

        try:
            self.assertTrue(os.path.exists(tmp_file))
            fp = urllib.urlopen(tmp_fileurl)
        finally:
            os.close(fd)
            fp.close()

On my laptop, urllib.urlopen raises a socket.gaierror.  This
means that the variable fp is never set, and the fp.close() at
line 235 raises an UnboundLoccalError, masking the socket error.

A quick fix would be:

        try:
            self.assertTrue(os.path.exists(tmp_file))
            fp = urllib.urlopen(tmp_fileurl)
            fp.close()
        finally:
            os.close(fd)

That way, the .close is only attempted if the open succeeds.
msg190447 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-06-01 14:59
New changeset 60c195e89c88 by Senthil Kumaran in branch '2.7':
Fix #16450 test_missing_localfile testcase fails on misconfigured hostname.
http://hg.python.org/cpython/rev/60c195e89c88
msg190448 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2013-06-01 15:03
I noticed this only after I had a misconfigured hostname on my mac.
Fixing my hostname of course solved the problem, but in any case, changed the tests so that we wont be baffled by the unexpected (and misdirected error msg) from test for misconfigured hostname.

Thanks for bug report, Hans Mulder and sorry for taking long time to get to this.
History
Date User Action Args
2013-06-01 15:03:13orsenthilsetstatus: open -> closed
type: behavior
messages: + msg190448

resolution: fixed
stage: resolved
2013-06-01 14:59:24python-devsetnosy: + python-dev
messages: + msg190447
2012-11-10 18:24:33orsenthilsetassignee: orsenthil

nosy: + orsenthil
2012-11-10 14:42:12HansMcreate