Skip to content
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_missing_localfile masks problems in urlopen #60654

Closed
HansM mannequin opened this issue Nov 10, 2012 · 3 comments
Closed

test_missing_localfile masks problems in urlopen #60654

HansM mannequin opened this issue Nov 10, 2012 · 3 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@HansM
Copy link
Mannequin

HansM mannequin commented Nov 10, 2012

BPO 16450
Nosy @orsenthil

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:

assignee = 'https://github.com/orsenthil'
closed_at = <Date 2013-06-01.15:03:13.814>
created_at = <Date 2012-11-10.14:42:12.073>
labels = ['type-bug', 'tests']
title = 'test_missing_localfile masks problems in urlopen'
updated_at = <Date 2013-06-01.15:03:13.813>
user = 'https://bugs.python.org/HansM'

bugs.python.org fields:

activity = <Date 2013-06-01.15:03:13.813>
actor = 'orsenthil'
assignee = 'orsenthil'
closed = True
closed_date = <Date 2013-06-01.15:03:13.814>
closer = 'orsenthil'
components = ['Tests']
creation = <Date 2012-11-10.14:42:12.073>
creator = 'HansM'
dependencies = []
files = []
hgrepos = []
issue_num = 16450
keywords = []
message_count = 3.0
messages = ['175278', '190447', '190448']
nosy_count = 3.0
nosy_names = ['orsenthil', 'python-dev', 'HansM']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue16450'
versions = ['Python 2.7']

@HansM
Copy link
Mannequin Author

HansM mannequin commented Nov 10, 2012

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.

@HansM HansM mannequin added the tests Tests in the Lib/test dir label Nov 10, 2012
@orsenthil orsenthil self-assigned this Nov 10, 2012
@python-dev
Copy link
Mannequin

python-dev mannequin commented Jun 1, 2013

New changeset 60c195e89c88 by Senthil Kumaran in branch '2.7':
Fix bpo-16450 test_missing_localfile testcase fails on misconfigured hostname.
http://hg.python.org/cpython/rev/60c195e89c88

@orsenthil
Copy link
Member

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.

@orsenthil orsenthil added the type-bug An unexpected behavior, bug, or error label Jun 1, 2013
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant