Skip to content

Commit 1f3efa1

Browse files
author
y-p
committed
Merge pull request #6174 from y-p/PR_more_network
More @network fixes
2 parents 3e31929 + a490ad4 commit 1f3efa1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pandas/io/tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
def setUp():
3+
import socket
4+
socket.setdefaulttimeout(5)

pandas/util/testing.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,13 @@ def dec(f):
967967

968968
return wrapper
969969

970+
# skip tests on exceptions with this message
971+
_network_error_messages = (
972+
'urlopen error timed out',
973+
'timeout: timed out'
974+
)
970975

976+
# or this e.errno/e.reason.errno
971977
_network_errno_vals = (
972978
101, # Network is unreachable
973979
110, # Connection timed out
@@ -976,6 +982,12 @@ def dec(f):
976982
60, # urllib.error.URLError: [Errno 60] Connection timed out
977983
)
978984

985+
# Both of the above shouldn't mask reasl issues such as 404's
986+
# or refused connections (changed DNS).
987+
# But some tests (test_data yahoo) contact incredibly flakey
988+
# servers.
989+
990+
# and conditionally raise on these exception types
979991
_network_error_classes = (IOError, httplib.HTTPException)
980992

981993
if sys.version_info[:2] >= (3,3):
@@ -1010,7 +1022,9 @@ def network(t, url="http://www.google.com",
10101022
raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
10111023
check_before_test=False,
10121024
error_classes=_network_error_classes,
1013-
skip_errnos=_network_errno_vals):
1025+
skip_errnos=_network_errno_vals,
1026+
_skip_on_messages=_network_error_messages,
1027+
):
10141028
"""
10151029
Label a test as requiring network connection and, if an error is
10161030
encountered, only raise if it does not find a network connection.
@@ -1108,6 +1122,10 @@ def wrapper(*args, **kwargs):
11081122
raise SkipTest("Skipping test due to known errno"
11091123
" and error %s" % e)
11101124

1125+
if any([m.lower() in str(e).lower() for m in _skip_on_messages]):
1126+
raise SkipTest("Skipping test because exception message is known"
1127+
" and error %s" % e)
1128+
11111129
if raise_on_error or can_connect(url, error_classes):
11121130
raise
11131131
else:

0 commit comments

Comments
 (0)