File tree 2 files changed +32
-10
lines changed
2 files changed +32
-10
lines changed Original file line number Diff line number Diff line change 19
19
fixtures_dir = os .path .realpath (os .path .join (current_dir , "fixtures" ))
20
20
21
21
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 (
23
50
fun ,
24
51
seconds = RETRY_TIMEOUT_SECONDS ,
25
52
* ,
@@ -43,11 +70,6 @@ def retry(
43
70
raises : bool
44
71
Wether or not to raise an exception on timeout. Defaults to ``True``.
45
72
46
- Returns
47
- -------
48
- bool
49
- True if time passed since retry() invoked less than seconds param.
50
-
51
73
Examples
52
74
--------
53
75
Original file line number Diff line number Diff line change 1
1
from time import time
2
2
import pytest
3
3
4
- from libtmux .test import retry , WaitTimeout
4
+ from libtmux .test import retry_until , WaitTimeout
5
5
6
6
7
7
def test_retry_three_times ():
@@ -18,7 +18,7 @@ def call_me_three_times():
18
18
19
19
return False
20
20
21
- retry (call_me_three_times , 1 )
21
+ retry_until (call_me_three_times , 1 )
22
22
23
23
end = time ()
24
24
@@ -32,7 +32,7 @@ def never_true():
32
32
return False
33
33
34
34
with pytest .raises (WaitTimeout ):
35
- retry (never_true , 1 )
35
+ retry_until (never_true , 1 )
36
36
37
37
end = time ()
38
38
@@ -45,7 +45,7 @@ def test_function_times_out_no_rise():
45
45
def never_true ():
46
46
return False
47
47
48
- retry (never_true , 1 , raises = False )
48
+ retry_until (never_true , 1 , raises = False )
49
49
50
50
end = time ()
51
51
You can’t perform that action at this time.
0 commit comments