Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def dec(f):

@optional_args
def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
error_classes=_network_error_classes):
error_classes=_network_error_classes, num_runs=2):
"""
Label a test as requiring network connection and skip test if it encounters a ``URLError``.

Expand All @@ -707,12 +707,15 @@ def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
----------
t : callable
The test requiring network connectivity.
raise_on_error : bool
raise_on_error : bool, optional
If True, never catches errors.
error_classes : iterable
error_classes : tuple, optional
error classes to ignore. If not in ``error_classes``, raises the error.
defaults to URLError. Be careful about changing the error classes here,
it may result in undefined behavior.
num_runs : int, optional
Number of times to run test. If fails on last try, will raise. Default
is 2 runs.

Returns
-------
Expand Down Expand Up @@ -754,17 +757,29 @@ def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
``pandas/util/testing.py`` sets the default behavior (currently False).
"""
from nose import SkipTest

if num_runs < 1:
raise ValueError("Must set at least 1 run")
t.network = True

@wraps(t)
def network_wrapper(*args, **kwargs):
if raise_on_error:
return t(*args, **kwargs)
else:
try:
return t(*args, **kwargs)
except error_classes as e:
raise SkipTest("Skipping test %s" % e)
for _ in range(num_runs):
try:
try:
return t(*args, **kwargs)
except error_classes as e:
raise SkipTest("Skipping test %s" % e)
except SkipTest:
raise
except Exception as e:
if runs < num_runs:
print("Failed: %r" % e)
else:
raise

return network_wrapper

Expand Down