Skip to content

Commit 5cf454a

Browse files
committed
Issue #22596: support.transient_internet() now also catches
ConnectionRefusedError exceptions wrapped by urllib.error.URLError. This change should fix sporadic failures in test_urllib2net.
1 parent 1e8ee14 commit 5cf454a

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Lib/test/support/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import tempfile
2626
import time
2727
import unittest
28+
import urllib.error
2829
import warnings
2930

3031
try:
@@ -1307,6 +1308,8 @@ def filter_error(err):
13071308
n = getattr(err, 'errno', None)
13081309
if (isinstance(err, socket.timeout) or
13091310
(isinstance(err, socket.gaierror) and n in gai_errnos) or
1311+
(isinstance(err, urllib.error.URLError) and
1312+
"ConnectionRefusedError" in err.reason) or
13101313
n in captured_errnos):
13111314
if not verbose:
13121315
sys.stderr.write(denied.args[0] + "\n")

Lib/test/test_urllib2net.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,14 @@ def _test_urls(self, urls, handlers, retry=True):
229229
with support.transient_internet(url):
230230
try:
231231
f = urlopen(url, req, TIMEOUT)
232+
# urllib.error.URLError is a subclass of OSError
232233
except OSError as err:
233234
if expected_err:
234235
msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
235236
(expected_err, url, req, type(err), err))
236237
self.assertIsInstance(err, expected_err, msg)
237238
else:
238239
raise
239-
except urllib.error.URLError as err:
240-
if isinstance(err[0], socket.timeout):
241-
print("<timeout: %s>" % url, file=sys.stderr)
242-
continue
243-
else:
244-
raise
245240
else:
246241
try:
247242
with support.time_out, \

0 commit comments

Comments
 (0)