From dcd2e2afc31d53c2b81cec97f94ccffc8f1729d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Tue, 21 Oct 2025 19:48:07 -0600 Subject: [PATCH] test: Ensure `exception` key is available for the `on_backoff` handler --- tests/test_backoff.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/test_backoff.py b/tests/test_backoff.py index 8f02ad2..800756a 100644 --- a/tests/test_backoff.py +++ b/tests/test_backoff.py @@ -11,6 +11,7 @@ import pytest import backoff +from backoff._typing import Details from tests.common import _save_target @@ -194,13 +195,35 @@ def test_on_exception_constant_iterable(monkeypatch): giveups = [] successes = [] + def on_backoff(details: Details): + nonlocal backoffs + assert details["tries"] == len(backoffs) + 1 + assert "exception" in details + assert isinstance(details["exception"], KeyError) + + backoffs.append(details) + + def on_giveup(details: Details): + nonlocal giveups + assert details["tries"] == 4 + assert "exception" in details + assert isinstance(details["exception"], KeyError) + + giveups.append(details) + + def on_success(details: Details): + nonlocal successes + + successes.append(details) + + @backoff.on_exception( backoff.constant, KeyError, interval=(1, 2, 3), - on_backoff=backoffs.append, - on_giveup=giveups.append, - on_success=successes.append, + on_backoff=on_backoff, + on_giveup=on_giveup, + on_success=on_success, ) def endless_exceptions(): raise KeyError('foo')