"""Unit tests for retry_on_exception decorator.""" import pytest from werkzeug.exceptions import Conflict from ledger.utils.retry import retry_on_exception def test_does_not_retry_http_exception(): """HTTPExceptions propagate immediately without retry.""" call_count = 0 @retry_on_exception(retries=3) def failing_fn(): nonlocal call_count call_count += 1 raise Conflict('duplicate') with pytest.raises(Conflict): failing_fn() assert call_count == 1 def test_retries_generic_exception(): """Generic exceptions are retried up to max attempts.""" call_count = 0 @retry_on_exception(retries=3, delay_secs=0) def failing_fn(): nonlocal call_count call_count += 1 raise RuntimeError('transient') with pytest.raises(RuntimeError): failing_fn() assert call_count == 3