From 1e22f309feb2909216911759dc8d31c6f43bca09 Mon Sep 17 00:00:00 2001 From: Robert Sigmundsson <230784065+RobertSigmundsson@users.noreply.github.com> Date: Sun, 11 Oct 2026 00:57:37 +0200 Subject: [PATCH] test(router): isolate the retry tests from module level fallbacks An earlier test in the same CI worker leaves litellm.default_fallbacks set, so an exhausted request made one extra call to the fallback and the attempt count was off by one. The router helper now clears the four module level fallback settings through monkeypatch --- tests/unit/test_router/test_router_retries.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_router/test_router_retries.py b/tests/unit/test_router/test_router_retries.py index 1ab007ef3c5..5077fdd322a 100644 --- a/tests/unit/test_router/test_router_retries.py +++ b/tests/unit/test_router/test_router_retries.py @@ -935,7 +935,17 @@ async def test_router_retry_num_retries_single_retry(): ), f"Expected max_retries to be 1, got {e.max_retries}" -def _single_deployment_router(num_retries: int) -> Router: +_MODULE_LEVEL_FALLBACKS: Final = ( + "default_fallbacks", + "fallbacks", + "context_window_fallbacks", + "content_policy_fallbacks", +) + + +def _single_deployment_router(num_retries: int, monkeypatch: pytest.MonkeyPatch) -> Router: + for name in _MODULE_LEVEL_FALLBACKS: + monkeypatch.setattr(litellm, name, None) return Router( model_list=[ { @@ -985,7 +995,7 @@ async def test_router_sleeps_only_before_a_retry_that_will_happen( num_retries: int, failed_attempts: int, expected_sleeps: int, monkeypatch: pytest.MonkeyPatch ) -> None: sleep: Final = _patch_asyncio_sleep(monkeypatch) - router: Final = _single_deployment_router(num_retries) + router: Final = _single_deployment_router(num_retries, monkeypatch) error: Final = litellm.InternalServerError(message="boom", model="retry-test-model", llm_provider="openai") attempts_exhausted: Final = failed_attempts > num_retries attempt: Final = _script_attempts( @@ -1008,7 +1018,7 @@ async def test_router_honours_retry_after_for_each_retry_but_not_after_the_last_ monkeypatch: pytest.MonkeyPatch, ) -> None: sleep: Final = _patch_asyncio_sleep(monkeypatch) - router: Final = _single_deployment_router(num_retries=3) + router: Final = _single_deployment_router(num_retries=3, monkeypatch=monkeypatch) retry_afters: Final = (10, 20, 30, 40) _script_attempts(router, monkeypatch, [_rate_limited(seconds) for seconds in retry_afters])