changeset: 93168:76ef82ec80a7 branch: 3.4 parent: 93166:a3481025a742 user: Berker Peksag date: Sat Oct 25 05:42:30 2014 +0300 files: Lib/test/support/__init__.py Lib/test/test_urllib2net.py description: Issue #22596: support.transient_internet() now also catches ConnectionRefusedError exceptions wrapped by urllib.error.URLError. This change should fix sporadic failures in test_urllib2net. diff -r a3481025a742 -r 76ef82ec80a7 Lib/test/support/__init__.py --- a/Lib/test/support/__init__.py Sat Oct 25 05:20:49 2014 +0300 +++ b/Lib/test/support/__init__.py Sat Oct 25 05:42:30 2014 +0300 @@ -25,6 +25,7 @@ import tempfile import time import unittest +import urllib.error import warnings try: @@ -1307,6 +1308,8 @@ 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 -r a3481025a742 -r 76ef82ec80a7 Lib/test/test_urllib2net.py --- a/Lib/test/test_urllib2net.py Sat Oct 25 05:20:49 2014 +0300 +++ b/Lib/test/test_urllib2net.py Sat Oct 25 05:42:30 2014 +0300 @@ -229,6 +229,7 @@ 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 @@ self.assertIsInstance(err, expected_err, msg) else: raise - except urllib.error.URLError as err: - if isinstance(err[0], socket.timeout): - print("" % url, file=sys.stderr) - continue - else: - raise else: try: with support.time_out, \