diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -43,7 +43,7 @@ __all__ = [ "findfile", "create_empty_file", "sortdict", "check_syntax_error", "open_urlresource", "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource", "captured_stdout", "captured_stdin", "captured_stderr", "time_out", - "socket_peer_reset", "ioerror_peer_reset", "run_with_locale", 'temp_umask', + "socket_peer_reset", "ioerror_peer_reset", "transient_errors", "run_with_locale", 'temp_umask', "transient_internet", "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", @@ -896,18 +896,21 @@ time_out = TransientResource(IOError, er socket_peer_reset = TransientResource(socket.error, errno=errno.ECONNRESET) ioerror_peer_reset = TransientResource(IOError, errno=errno.ECONNRESET) +transient_errors = tuple( + getattr(errno, name, num) + for (name, num) in ( + ('ECONNREFUSED', 111), + ('ECONNRESET', 104), + ('EHOSTUNREACH', 113), + ('ENETUNREACH', 101), + ('ETIMEDOUT', 110), + ) +) @contextlib.contextmanager def transient_internet(resource_name, *, timeout=30.0, errnos=()): """Return a context manager that raises ResourceDenied when various issues with the Internet connection manifest themselves as exceptions.""" - default_errnos = [ - ('ECONNREFUSED', 111), - ('ECONNRESET', 104), - ('EHOSTUNREACH', 113), - ('ENETUNREACH', 101), - ('ETIMEDOUT', 110), - ] default_gai_errnos = [ ('EAI_NONAME', -2), ('EAI_NODATA', -5), @@ -919,8 +922,7 @@ def transient_internet(resource_name, *, captured_errnos = errnos gai_errnos = [] if not captured_errnos: - captured_errnos = [getattr(errno, name, num) - for (name, num) in default_errnos] + captured_errnos = transient_errors gai_errnos = [getattr(socket, name, num) for (name, num) in default_gai_errnos] diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -492,7 +492,11 @@ class NetworkedTests(unittest.TestCase): cert_reqs=ssl.CERT_REQUIRED, ca_certs=SVN_PYTHON_ORG_ROOT_CERT) try: - self.assertEqual(0, s.connect_ex(("svn.python.org", 443))) + err = s.connect_ex(("svn.python.org", 443)) + if err in support.transient_errors: + self.skipTest("fail to connect to svn.python.org " + "(errno %s)" % err) + self.assertEqual(err, 0) self.assertTrue(s.getpeercert()) finally: s.close()