File tree Expand file tree Collapse file tree 2 files changed +32
-10
lines changed Expand file tree Collapse file tree 2 files changed +32
-10
lines changed Original file line number Diff line number Diff line change 1919fixtures_dir = os .path .realpath (os .path .join (current_dir , "fixtures" ))
2020
2121
22- def retry (
22+ def retry (seconds = RETRY_TIMEOUT_SECONDS ):
23+ """
24+ Retry a block of code until a time limit or ``break``.
25+
26+ Parameters
27+ ----------
28+ seconds : int
29+ Seconds to retry, defaults to ``RETRY_TIMEOUT_SECONDS``, which is
30+ configurable via environmental variables.
31+
32+ Returns
33+ -------
34+ bool
35+ True if time passed since retry() invoked less than seconds param.
36+
37+ Examples
38+ --------
39+
40+ >>> while retry():
41+ ... p = w.attached_pane
42+ ... p.server._update_panes()
43+ ... if p.current_path == pane_path:
44+ ... break
45+ """
46+ return (lambda : time .time () < time .time () + seconds )()
47+
48+
49+ def retry_until (
2350 fun ,
2451 seconds = RETRY_TIMEOUT_SECONDS ,
2552 * ,
@@ -43,11 +70,6 @@ def retry(
4370 raises : bool
4471 Wether or not to raise an exception on timeout. Defaults to ``True``.
4572
46- Returns
47- -------
48- bool
49- True if time passed since retry() invoked less than seconds param.
50-
5173 Examples
5274 --------
5375
Original file line number Diff line number Diff line change 11from time import time
22import pytest
33
4- from libtmux .test import retry , WaitTimeout
4+ from libtmux .test import retry_until , WaitTimeout
55
66
77def test_retry_three_times ():
@@ -18,7 +18,7 @@ def call_me_three_times():
1818
1919 return False
2020
21- retry (call_me_three_times , 1 )
21+ retry_until (call_me_three_times , 1 )
2222
2323 end = time ()
2424
@@ -32,7 +32,7 @@ def never_true():
3232 return False
3333
3434 with pytest .raises (WaitTimeout ):
35- retry (never_true , 1 )
35+ retry_until (never_true , 1 )
3636
3737 end = time ()
3838
@@ -45,7 +45,7 @@ def test_function_times_out_no_rise():
4545 def never_true ():
4646 return False
4747
48- retry (never_true , 1 , raises = False )
48+ retry_until (never_true , 1 , raises = False )
4949
5050 end = time ()
5151
You can’t perform that action at this time.
0 commit comments