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
This commit is contained in:
Robert Sigmundsson 2026-10-11 00:57:37 +02:00
parent 54b56a40d0
commit 1e22f309fe

View file

@ -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])