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

ftp tests in test_urllib2net should skip on unreachable network #87730

Closed
carljm opened this issue Mar 19, 2021 · 2 comments
Closed

ftp tests in test_urllib2net should skip on unreachable network #87730

carljm opened this issue Mar 19, 2021 · 2 comments
Labels
3.10 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@carljm
Copy link
Member

carljm commented Mar 19, 2021

BPO 43564
Nosy @orsenthil, @giampaolo, @carljm, @brandtbucher
PRs
  • bpo-43564: preserve original exception in args of FTP URLError #24938
  • 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 = None
    closed_at = None
    created_at = <Date 2021-03-19.21:21:09.420>
    labels = ['type-bug', 'tests', '3.10']
    title = 'ftp tests in test_urllib2net should skip on unreachable network'
    updated_at = <Date 2021-06-23.19:18:02.469>
    user = 'https://github.com/carljm'

    bugs.python.org fields:

    activity = <Date 2021-06-23.19:18:02.469>
    actor = 'brandtbucher'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tests']
    creation = <Date 2021-03-19.21:21:09.420>
    creator = 'carljm'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43564
    keywords = ['patch']
    message_count = 2.0
    messages = ['389115', '389116']
    nosy_count = 4.0
    nosy_names = ['orsenthil', 'giampaolo.rodola', 'carljm', 'brandtbucher']
    pr_nums = ['24938']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43564'
    versions = ['Python 3.10']

    @carljm
    Copy link
    Member Author

    carljm commented Mar 19, 2021

    In general it seems the CPython test suite takes care to skip instead of failing networked tests when the network is unavailable (c.f. support.transient_internet test helper).

    In this case of the 5 FTP tests in test_urllib2net (that is, test_ftp, test_ftp_basic, test_ftp_default_timeout, test_ftp_no_timeout, and test_ftp_timeout), even though they use support_transient_internet, they still fail if the network is unavailable.

    The reason is that they make calls which end up raising an exception in the form URLError("ftp error: OSError(101, 'Network is unreachable')" -- the original OSError is flattened into the exception string message, but is otherwise not in the exception args. This means that transient_network does not detect it as a suppressable exception.

    It seems like many uses of URLError in urllib pass the original OSError directly to URLError.__init__(), which means it ends up in args and the unwrapping code in transient_internet is able to find the original OSError. But the ftp code instead directly interpolates the OSError into a new message string.

    @carljm carljm added 3.10 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Mar 19, 2021
    @carljm carljm changed the title some tests in test_urllib2net fail instead of skipping on unreachable network ftp tests in test_urllib2net fail instead of skipping on unreachable network Mar 19, 2021
    @carljm carljm changed the title some tests in test_urllib2net fail instead of skipping on unreachable network ftp tests in test_urllib2net fail instead of skipping on unreachable network Mar 19, 2021
    @carljm
    Copy link
    Member Author

    carljm commented Mar 19, 2021

    Created a PR that fixes this by being more consistent in how urllib wraps network errors. If there are backward-compatibility concerns with this change, another option could be some really ugly regex-matching code in test.support.transient_internet.

    @terryjreedy terryjreedy changed the title ftp tests in test_urllib2net fail instead of skipping on unreachable network ftp tests in test_urllib2net should skip on unreachable network Mar 26, 2021
    @terryjreedy terryjreedy changed the title ftp tests in test_urllib2net fail instead of skipping on unreachable network ftp tests in test_urllib2net should skip on unreachable network Mar 26, 2021
    @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
    3.10 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants