@@ -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
981993if 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