summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2014-10-25 02:42:30 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2014-10-25 02:42:30 (GMT)
commit8b63d3af9f08c984331629c726d05794a1bbfc4a (patch)
tree50498c800837f150d7442686f89ea86463c1e975 /Lib
parent6d1c149a46f274392d2d2adda998e64017e42030 (diff)
downloadcpython-8b63d3af9f08c984331629c726d05794a1bbfc4a.zip
cpython-8b63d3af9f08c984331629c726d05794a1bbfc4a.tar.gz
cpython-8b63d3af9f08c984331629c726d05794a1bbfc4a.tar.bz2
Issue #22596: support.transient_internet() now also catches
ConnectionRefusedError exceptions wrapped by urllib.error.URLError. This change should fix sporadic failures in test_urllib2net.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support/__init__.py3
-rw-r--r--Lib/test/test_urllib2net.py7
2 files changed, 4 insertions, 6 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index f2c1a92..adebedd 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -25,6 +25,7 @@ import sysconfig
import tempfile
import time
import unittest
+import urllib.error
import warnings
try:
@@ -1307,6 +1308,8 @@ def transient_internet(resource_name, *, timeout=30.0, errnos=()):
n = getattr(err, 'errno', None)
if (isinstance(err, socket.timeout) or
(isinstance(err, socket.gaierror) and n in gai_errnos) or
+ (isinstance(err, urllib.error.URLError) and
+ "ConnectionRefusedError" in err.reason) or
n in captured_errnos):
if not verbose:
sys.stderr.write(denied.args[0] + "\n")
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index 51b7fc5..6f78cea 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -229,6 +229,7 @@ class OtherNetworkTests(unittest.TestCase):
with support.transient_internet(url):
try:
f = urlopen(url, req, TIMEOUT)
+ # urllib.error.URLError is a subclass of OSError
except OSError as err:
if expected_err:
msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
@@ -236,12 +237,6 @@ class OtherNetworkTests(unittest.TestCase):
self.assertIsInstance(err, expected_err, msg)
else:
raise
- except urllib.error.URLError as err:
- if isinstance(err[0], socket.timeout):
- print("<timeout: %s>" % url, file=sys.stderr)
- continue
- else:
- raise
else:
try:
with support.time_out, \