From 7dcef86cc66d547980eee7c9f52e2a61273b1409 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Mon, 26 Jan 2026 02:30:27 -0300 Subject: [PATCH] Fix test_embedding_header_forwarding_with_model_group for parallel test execution - Reload litellm_pre_call_utils module inside test to get fresh litellm reference - Use string-based patch("litellm.model_group_settings") instead of patch.object - These changes ensure the patch targets the correct module after conftest reloads litellm --- .../proxy/test_litellm_pre_call_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py index 25ae2ec825d..452db3902c0 100644 --- a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py +++ b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py @@ -1347,9 +1347,18 @@ async def test_embedding_header_forwarding_with_model_group(): This test verifies the fix for embedding endpoints not forwarding headers similar to how chat completion endpoints do. """ - # Import the module that add_litellm_data_to_request uses to access litellm + import importlib + import litellm.proxy.litellm_pre_call_utils as pre_call_utils_module + # Reload the module to ensure it has a fresh reference to litellm + # This is necessary because conftest.py reloads litellm at module scope, + # which can cause the module's litellm reference to become stale + importlib.reload(pre_call_utils_module) + + # Re-import the function after reload to get the fresh version + from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request + # Setup mock request for embeddings request_mock = MagicMock(spec=Request) request_mock.url.path = "/v1/embeddings" @@ -1380,10 +1389,10 @@ async def test_embedding_header_forwarding_with_model_group(): ) # Mock model_group_settings to enable header forwarding for the model - # Use patch to ensure we modify the litellm reference that pre_call_utils actually uses + # Use string-based patch to ensure we patch the current sys.modules['litellm'] # This avoids issues with module reloading during parallel test execution mock_settings = MagicMock(forward_client_headers_to_llm_api=["local-openai/*"]) - with patch.object(pre_call_utils_module.litellm, "model_group_settings", mock_settings): + with patch("litellm.model_group_settings", mock_settings): # Call add_litellm_data_to_request which includes header forwarding logic updated_data = await add_litellm_data_to_request( data=data,