diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-04-15 10:34:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-15 10:34:53 (GMT) |
commit | 3c7931e514faf509a39c218c2c9f55efb434628f (patch) | |
tree | 0c4bdae0b4ecd84d1ea036893ed70747137ee3f6 /Lib/test/support | |
parent | f1464f4d2ecf9b809ff768c523c5eea1abd31c55 (diff) | |
download | cpython-3c7931e514faf509a39c218c2c9f55efb434628f.zip cpython-3c7931e514faf509a39c218c2c9f55efb434628f.tar.gz cpython-3c7931e514faf509a39c218c2c9f55efb434628f.tar.bz2 |
bpo-36629: Add support.get_socket_conn_refused_errs() (GH-12834)
Fix test_imap4_host_default_value() of test_imaplib: catch also
errno.ENETUNREACH error.
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 5bd15a2..2bb561b 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1477,6 +1477,22 @@ socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) ioerror_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) +def get_socket_conn_refused_errs(): + """ + Get the different socket error numbers ('errno') which can be received + when a connection is refused. + """ + errors = [errno.ECONNREFUSED] + if hasattr(errno, 'ENETUNREACH'): + # On Solaris, ENETUNREACH is returned sometimes instead of ECONNREFUSED + errors.append(errno.ENETUNREACH) + if hasattr(errno, 'EADDRNOTAVAIL'): + # bpo-31910: socket.create_connection() fails randomly + # with EADDRNOTAVAIL on Travis CI + errors.append(errno.EADDRNOTAVAIL) + return errors + + @contextlib.contextmanager def transient_internet(resource_name, *, timeout=30.0, errnos=()): """Return a context manager that raises ResourceDenied when various issues |