@@ -692,7 +692,7 @@ def dec(f):
692
692
693
693
@optional_args
694
694
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 ):
696
696
"""
697
697
Label a test as requiring network connection and skip test if it encounters a ``URLError``.
698
698
@@ -707,12 +707,15 @@ def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
707
707
----------
708
708
t : callable
709
709
The test requiring network connectivity.
710
- raise_on_error : bool
710
+ raise_on_error : bool, optional
711
711
If True, never catches errors.
712
- error_classes : iterable
712
+ error_classes : tuple, optional
713
713
error classes to ignore. If not in ``error_classes``, raises the error.
714
714
defaults to URLError. Be careful about changing the error classes here,
715
715
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.
716
719
717
720
Returns
718
721
-------
@@ -754,17 +757,29 @@ def network(t, raise_on_error=_RAISE_NETWORK_ERROR_DEFAULT,
754
757
``pandas/util/testing.py`` sets the default behavior (currently False).
755
758
"""
756
759
from nose import SkipTest
760
+
761
+ if num_runs < 1 :
762
+ raise ValueError ("Must set at least 1 run" )
757
763
t .network = True
758
764
759
765
@wraps (t )
760
766
def network_wrapper (* args , ** kwargs ):
761
767
if raise_on_error :
762
768
return t (* args , ** kwargs )
763
769
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
768
783
769
784
return network_wrapper
770
785
0 commit comments