Skip to content

Commit 6d9fa7f

Browse files
committed
Merge pull request #4369 from jtratner/make-network-tests-run-twice
TST: Make network tests run twice
2 parents 19c8874 + d605b5f commit 6d9fa7f

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

pandas/util/testing.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def dec(f):
692692

693693
@optional_args
694694
def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
695-
error_classes=_network_error_classes):
695+
error_classes=_network_error_classes, num_runs=2):
696696
"""
697697
Label a test as requiring network connection and skip test if it encounters a ``URLError``.
698698
@@ -707,12 +707,15 @@ def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
707707
----------
708708
t : callable
709709
The test requiring network connectivity.
710-
raise_on_error : bool
710+
raise_on_error : bool, optional
711711
If True, never catches errors.
712-
error_classes : iterable
712+
error_classes : tuple, optional
713713
error classes to ignore. If not in ``error_classes``, raises the error.
714714
defaults to URLError. Be careful about changing the error classes here,
715715
it may result in undefined behavior.
716+
num_runs : int, optional
717+
Number of times to run test. If fails on last try, will raise. Default
718+
is 2 runs.
716719
717720
Returns
718721
-------
@@ -754,17 +757,29 @@ def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
754757
``pandas/util/testing.py`` sets the default behavior (currently False).
755758
"""
756759
from nose import SkipTest
760+
761+
if num_runs < 1:
762+
raise ValueError("Must set at least 1 run")
757763
t.network = True
758764

759765
@wraps(t)
760766
def network_wrapper(*args, **kwargs):
761767
if raise_on_error:
762768
return t(*args, **kwargs)
763769
else:
764-
try:
765-
return t(*args, **kwargs)
766-
except error_classes as e:
767-
raise SkipTest("Skipping test %s" % e)
770+
for _ in range(num_runs):
771+
try:
772+
try:
773+
return t(*args, **kwargs)
774+
except error_classes as e:
775+
raise SkipTest("Skipping test %s" % e)
776+
except SkipTest:
777+
raise
778+
except Exception as e:
779+
if runs < num_runs:
780+
print("Failed: %r" % e)
781+
else:
782+
raise
768783

769784
return network_wrapper
770785

0 commit comments

Comments
 (0)