-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_retry.py
73 lines (49 loc) · 1.37 KB
/
test_retry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pytest
from indico.http.retry import retry
def test_no_errors() -> None:
@retry(Exception)
def no_errors() -> bool:
return True
assert no_errors()
def test_raises_errors() -> None:
calls = 0
@retry(RuntimeError, count=4, wait=0)
def raises_errors() -> None:
nonlocal calls
calls += 1
raise RuntimeError()
with pytest.raises(RuntimeError):
raises_errors()
assert calls == 5
def test_raises_other_errors() -> None:
calls = 0
@retry(RuntimeError, count=4, wait=0)
def raises_errors() -> None:
nonlocal calls
calls += 1
raise ValueError()
with pytest.raises(ValueError):
raises_errors()
assert calls == 1
@pytest.mark.asyncio
async def test_raises_errors_async() -> None:
calls = 0
@retry(RuntimeError, count=4, wait=0)
async def raises_errors() -> None:
nonlocal calls
calls += 1
raise RuntimeError()
with pytest.raises(RuntimeError):
await raises_errors()
assert calls == 5
@pytest.mark.asyncio
async def test_raises_other_errors_async() -> None:
calls = 0
@retry(RuntimeError, count=4, wait=0)
async def raises_errors() -> None:
nonlocal calls
calls += 1
raise ValueError()
with pytest.raises(ValueError):
await raises_errors()
assert calls == 1