classification
Title: ftp tests in test_urllib2net should skip on unreachable network
Type: behavior Stage: patch review
Components: Tests Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brandtbucher, carljm, giampaolo.rodola, orsenthil
Priority: normal Keywords: patch

Created on 2021-03-19 21:21 by carljm, last changed 2021-06-23 19:18 by brandtbucher.

Pull Requests
URL Status Linked Edit
PR 24938 open carljm, 2021-03-19 21:26
Messages (2)
msg389115 - (view) Author: Carl Meyer (carljm) * Date: 2021-03-19 21:21
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.
msg389116 - (view) Author: Carl Meyer (carljm) * Date: 2021-03-19 21:28
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`.
History
Date User Action Args
2021-06-23 19:18:02brandtbuchersetnosy: + brandtbucher
2021-03-26 18:46:47terry.reedysettitle: ftp tests in test_urllib2net fail instead of skipping on unreachable network -> ftp tests in test_urllib2net should skip on unreachable network
2021-03-26 18:46:08terry.reedysetnosy: + orsenthil, giampaolo.rodola
2021-03-19 21:28:09carljmsetmessages: + msg389116
2021-03-19 21:26:52carljmsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23699
2021-03-19 21:21:16carljmsettitle: some tests in test_urllib2net fail instead of skipping on unreachable network -> ftp tests in test_urllib2net fail instead of skipping on unreachable network
2021-03-19 21:21:09carljmcreate