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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: prevent sys.modules["langfuse"] import failures in langfuse unit tests
Julio Quinteros Prodc003e2a94c7
diff --git a/tests/test_litellm/integrations/langfuse/test_langfuse_prompt_management.py b/tests/test_litellm/integrations/langfuse/test_langfuse_prompt_management.pyindex 5389cdf7377..c557bdb67ee 100644--- a/tests/test_litellm/integrations/langfuse/test_langfuse_prompt_management.py+++ b/tests/test_litellm/integrations/langfuse/test_langfuse_prompt_management.py@@ -1,5 +1,5 @@import os-from unittest.mock import patch+from unittest.mock import MagicMock, patchfrom litellm.integrations.langfuse.langfuse_prompt_management import (LangfusePromptManagement,@@ -7,6 +7,20 @@ from litellm.integrations.langfuse.langfuse_prompt_management import (class TestLangfusePromptManagement:+ def setup_method(self):+ # Mock langfuse package to avoid triggering real import.+ # The real langfuse import fails on Python 3.14 due to pydantic v1 incompatibility.+ # This also prevents test-ordering issues when earlier tests remove sys.modules["langfuse"].+ self._mock_langfuse = MagicMock()+ self._mock_langfuse.version.__version__ = "3.0.0"+ self._langfuse_patcher = patch.dict(+ "sys.modules", {"langfuse": self._mock_langfuse}+ )+ self._langfuse_patcher.start()++ def teardown_method(self):+ self._langfuse_patcher.stop()+def test_get_prompt_from_id(self):langfuse_prompt_management = LangfusePromptManagement()with patch.object(diff --git a/tests/test_litellm/integrations/test_langfuse.py b/tests/test_litellm/integrations/test_langfuse.pyindex 8da7dd8917b..77ff5dbb97e 100644--- a/tests/test_litellm/integrations/test_langfuse.py+++ b/tests/test_litellm/integrations/test_langfuse.py@@ -472,8 +472,15 @@ def test_max_langfuse_clients_limit():"""Test that the max langfuse clients limit is respected when initializing multiple clients"""+ # Mock langfuse package to avoid triggering real import.+ # The real langfuse import fails on Python 3.14 due to pydantic v1 incompatibility,+ # and sys.modules["langfuse"] may be absent after other tests in the suite clean up.+ mock_langfuse = MagicMock()+ mock_langfuse.version.__version__ = "3.0.0"# Set max clients to 2 for testing- with patch.object(langfuse_module, "MAX_LANGFUSE_INITIALIZED_CLIENTS", 2):+ with patch.dict("sys.modules", {"langfuse": mock_langfuse}), patch.object(+ langfuse_module, "MAX_LANGFUSE_INITIALIZED_CLIENTS", 2+ ):# Reset the counterlitellm.initialized_langfuse_clients = 0diff --git a/tests/test_litellm/integrations/test_langfuse_otel.py b/tests/test_litellm/integrations/test_langfuse_otel.pyindex 62851b8f99f..44853d9dce5 100644--- a/tests/test_litellm/integrations/test_langfuse_otel.py+++ b/tests/test_litellm/integrations/test_langfuse_otel.py@@ -161,7 +161,7 @@ class TestLangfuseOtelIntegration:# Use monkeypatch so the real module is restored after the test runs,# preventing sys.modules corruption that would break patch() targets in# later tests (the patch would hit the stub while the real module's- # globals remain unpatch-ed).+ # globals remain unpatched).monkeypatch.setitem(sys.modules, "litellm.integrations.langfuse.langfuse", stub_module) # type: ignorekwargs = {"litellm_params": {"metadata": {"foo": "bar"}}}