• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LostInDarkMath / pedantic-python-decorators / 8939405696

03 May 2024 01:01PM UTC coverage: 95.502%. First build
8939405696

Pull #96

github

web-flow
Merge dc80601b9 into df1b566be
Pull Request #96: Close `multiprocess.connection.Connection` correctly in `@in_subproce…

2031 of 2056 branches covered (98.78%)

Branch coverage included in aggregate %.

35 of 74 new or added lines in 4 files covered. (47.3%)

6716 of 7103 relevant lines covered (94.55%)

1.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.61
/pedantic/tests/test_retry.py
1
import unittest
2✔
2

3
from pedantic import retry
2✔
4
from pedantic.decorators.fn_deco_retry import retry_func
2✔
5

6

7
class TestRetry(unittest.TestCase):
2✔
8
    def test_retry_positive_no_args(self):
2✔
9
        count = 0
2✔
10

11
        @retry(attempts=5)
2✔
12
        def foo():
2✔
13
            nonlocal count
14
            count += 1
2✔
15

16
        foo()
2✔
17
        assert count == 1
2✔
18

19
    def test_retry_positive_args_and_kwargs(self):
2✔
20
        count = 0
2✔
21

22
        @retry(attempts=5)
2✔
23
        def foo(x, y):
2✔
24
            nonlocal count
25
            count += x + y
2✔
26

27
        foo(12, y=42)
2✔
28
        assert count == 54
2✔
29

30
    def test_retry_positive_no_args_fails_every_time(self):
2✔
31
        count = 0
2✔
32

33
        @retry(attempts=5)
2✔
34
        def foo():
2✔
35
            nonlocal count
36
            count += 1
2✔
37
            raise ValueError('foo')
2✔
38

39
        with self.assertRaises(ValueError):
2✔
40
            foo()
2✔
41

42
        assert count == 5
2✔
43

44
    def test_retry_positive_no_args_fails_different_exception_type(self):
2✔
45
        count = 0
2✔
46

47
        @retry(attempts=5, exceptions=AssertionError)
2✔
48
        def foo():
2✔
49
            nonlocal count
50
            count += 1
2✔
51
            raise ValueError('foo')
2✔
52

53
        with self.assertRaises(ValueError):
2✔
54
            foo()
2✔
55

56
        assert count == 1
2✔
57

58
    def test_retry_fails_same_exception_type(self):
2✔
59
        count = 0
2✔
60

61
        @retry(attempts=5, exceptions=AssertionError)
2✔
62
        def foo():
2✔
63
            nonlocal count
64
            count += 1
2✔
65
            raise AssertionError('foo')
2✔
66

67
        with self.assertRaises(AssertionError):
2✔
68
            foo()
2✔
69

70
        assert count == 5
2✔
71

72
    def test_retry_positive_no_args_fails_on_first_times(self):
2✔
73
        count = 0
2✔
74

75
        @retry(attempts=5)
2✔
76
        def foo() -> int:
2✔
77
            nonlocal count
78
            count += 1
2✔
79

80
            if count < 3:
2✔
81
                raise ValueError('foo')
2✔
82

83
            return count
2✔
84

85
        assert foo() == 3
2✔
86
        assert count == 3
2✔
87

88

89
class TestRetryFunc(unittest.TestCase):
2✔
90
    def test_retry_positive_no_args(self):
2✔
NEW
91
        count = 0
×
92

NEW
93
        def foo():
×
94
            nonlocal count
NEW
95
            count += 1
×
96

NEW
97
        retry_func(func=foo, attempts=5)
×
NEW
98
        assert count == 1
×
99

100
    def test_retry_positive_args_and_kwargs(self):
2✔
NEW
101
        count = 0
×
102

NEW
103
        def foo(x, y):
×
104
            nonlocal count
NEW
105
            count += x + y
×
106

NEW
107
        retry_func(foo, 12, attempts=5, y=42)
×
NEW
108
        assert count == 54
×
109

110
    def test_retry_positive_no_args_fails_every_time(self):
2✔
NEW
111
        count = 0
×
112

NEW
113
        def foo():
×
114
            nonlocal count
NEW
115
            count += 1
×
NEW
116
            raise ValueError('foo')
×
117

NEW
118
        with self.assertRaises(ValueError):
×
NEW
119
            retry_func(func=foo, attempts=5)
×
120

NEW
121
        assert count == 5
×
122

123
    def test_retry_positive_no_args_fails_different_exception_type(self):
2✔
NEW
124
        count = 0
×
125

NEW
126
        def foo():
×
127
            nonlocal count
NEW
128
            count += 1
×
NEW
129
            raise ValueError('foo')
×
130

NEW
131
        with self.assertRaises(ValueError):
×
NEW
132
            retry_func(func=foo, attempts=5, exceptions=AssertionError)
×
133

NEW
134
        assert count == 1
×
135

136
    def test_retry_fails_same_exception_type(self):
2✔
NEW
137
        count = 0
×
138

NEW
139
        def foo():
×
140
            nonlocal count
NEW
141
            count += 1
×
NEW
142
            raise AssertionError('foo')
×
143

NEW
144
        with self.assertRaises(AssertionError):
×
NEW
145
            retry_func(func=foo, attempts=5, exceptions=AssertionError)
×
146

NEW
147
        assert count == 5
×
148

149
    def test_retry_positive_no_args_fails_on_first_times(self):
2✔
NEW
150
        count = 0
×
151

NEW
152
        def foo() -> int:
×
153
            nonlocal count
NEW
154
            count += 1
×
155

NEW
156
            if count < 3:
×
NEW
157
                raise ValueError('foo')
×
158

NEW
159
            return count
×
160

NEW
161
        assert retry_func(func=foo, attempts=5) == 3
×
NEW
162
        assert count == 3
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc