Skip to content

Commit 3fe215c

Browse files
test: Ensure exception key is available for the on_backoff handler (#36)
1 parent 0c13f22 commit 3fe215c

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

tests/test_backoff.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pytest
1212

1313
import backoff
14+
from backoff._typing import Details
1415
from tests.common import _save_target
1516

1617

@@ -194,13 +195,35 @@ def test_on_exception_constant_iterable(monkeypatch):
194195
giveups = []
195196
successes = []
196197

198+
def on_backoff(details: Details):
199+
nonlocal backoffs
200+
assert details["tries"] == len(backoffs) + 1
201+
assert "exception" in details
202+
assert isinstance(details["exception"], KeyError)
203+
204+
backoffs.append(details)
205+
206+
def on_giveup(details: Details):
207+
nonlocal giveups
208+
assert details["tries"] == 4
209+
assert "exception" in details
210+
assert isinstance(details["exception"], KeyError)
211+
212+
giveups.append(details)
213+
214+
def on_success(details: Details):
215+
nonlocal successes
216+
217+
successes.append(details)
218+
219+
197220
@backoff.on_exception(
198221
backoff.constant,
199222
KeyError,
200223
interval=(1, 2, 3),
201-
on_backoff=backoffs.append,
202-
on_giveup=giveups.append,
203-
on_success=successes.append,
224+
on_backoff=on_backoff,
225+
on_giveup=on_giveup,
226+
on_success=on_success,
204227
)
205228
def endless_exceptions():
206229
raise KeyError('foo')

0 commit comments

Comments
 (0)