From 60295135dd9fb0ccce830f239f70ca01f147a439 Mon Sep 17 00:00:00 2001 From: Christopher Krah <48338417+chrikrah@users.noreply.github.com> Date: Mon, 12 Oct 2026 08:29:29 +0200 Subject: [PATCH] test(router): stop test_default_model_fallbacks leaking litellm.default_fallbacks The litellm_module_fallbacks=True cases assigned litellm.default_fallbacks directly and never put it back. isolate_litellm_globals does not reset that global, so any later test in the same process that builds a Router without default_fallbacks inherits ["my-good-model"]. In collection order that fails test_has_default_fallbacks[False-False] and test_get_first_default_fallback in test_router_helper_utils.py. Set it through monkeypatch so it is restored at teardown. --- tests/unit/test_router/test_router_fallbacks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_router/test_router_fallbacks.py b/tests/unit/test_router/test_router_fallbacks.py index 88d89696297..5ae0a83e8b2 100644 --- a/tests/unit/test_router/test_router_fallbacks.py +++ b/tests/unit/test_router/test_router_fallbacks.py @@ -77,14 +77,14 @@ async def test_async_fallbacks_streaming(): @pytest.mark.parametrize("sync_mode", [True, False]) @pytest.mark.parametrize("litellm_module_fallbacks", [True, False]) @pytest.mark.asyncio -async def test_default_model_fallbacks(sync_mode, litellm_module_fallbacks): +async def test_default_model_fallbacks(sync_mode, litellm_module_fallbacks, monkeypatch: pytest.MonkeyPatch): """ Related issue - https://github.com/BerriAI/litellm/issues/3623 If model misconfigured, setup a default model for generic fallback """ if litellm_module_fallbacks: - litellm.default_fallbacks = ["my-good-model"] + monkeypatch.setattr(litellm, "default_fallbacks", ["my-good-model"]) router = Router( model_list=[ {