Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix HuggingFace embedding tests for parallel test execution

Julio Quinteros Pro8285a2a7b4c8
diff --git a/tests/test_litellm/llms/huggingface/embedding/test_huggingface_embedding_handler.py b/tests/test_litellm/llms/huggingface/embedding/test_huggingface_embedding_handler.py
index f6bc983df01..090792d4f0b 100644
--- a/tests/test_litellm/llms/huggingface/embedding/test_huggingface_embedding_handler.py
+++ b/tests/test_litellm/llms/huggingface/embedding/test_huggingface_embedding_handler.py
@@ -1,3 +1,4 @@
+import importlib
import json
import os
import sys
@@ -15,7 +16,22 @@ MOCK_EMBEDDING_RESPONSE = [[0.1, 0.2, 0.3, 0.4, 0.5]]
@pytest.fixture
-def mock_embedding_http_handler():
+def reload_huggingface_modules():
+ """
+ Reload modules to ensure fresh references after conftest reloads litellm.
+ This ensures the HTTPHandler class being patched is the same one used by
+ the embedding handler during parallel test execution.
+ """
+ import litellm.llms.custom_httpx.http_handler as http_handler_module
+ import litellm.llms.huggingface.embedding.handler as hf_embedding_handler_module
+
+ importlib.reload(http_handler_module)
+ importlib.reload(hf_embedding_handler_module)
+ yield
+
+
+def mock_embedding_http_handler(reload_huggingface_modules):
"""Fixture to mock the HTTP handler for embedding tests"""
with patch("litellm.llms.custom_httpx.http_handler.HTTPHandler.post") as mock_post:
mock_response = MagicMock()
@@ -27,7 +43,7 @@ def mock_embedding_http_handler():
@pytest.fixture
-def mock_embedding_async_http_handler():
+def mock_embedding_async_http_handler(reload_huggingface_modules):
"""Fixture to mock the async HTTP handler for embedding tests"""
with patch("litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler.post", new_callable=AsyncMock) as mock_post:
mock_response = MagicMock()