Skip to content

test_missing_localfile masks problems in urlopen #60654

Closed

Description

@HansM
mannequin
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']

Activity

  1. HansM commented on Nov 10, 2012

    HansMmannequin
    MannequinAuthor

    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.

  2. self-assigned this
    on Nov 10, 2012
  3. python-dev commented on Jun 1, 2013

    python-devmannequin
    Mannequin

    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

  4. orsenthil commented on Jun 1, 2013

    @orsenthil
    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.

  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions