File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change 1111import pytest
1212
1313import backoff
14+ from backoff ._typing import Details
1415from 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' )
You can’t perform that action at this time.
0 commit comments