From 6ce403ccbe3041117a027d19c0a00b07900b9190 Mon Sep 17 00:00:00 2001 From: Yucheng Zhu Date: Wed, 26 Aug 2026 12:38:58 -0700 Subject: [PATCH] fix(lint): remove duplicate test import, LIT002 dict literal, and mock-echo otel test - drop redundant in-function import of callback_config_error (F811) - avoid the `or {}` mutable literal in _set_langfuse_specific_attributes (LIT002) - rewrite the dynamic-env otel test to observe span.set_attribute output instead of patching litellm internals (TQ002/TQ008) Co-Authored-By: Claude Fable 5 --- .../integrations/langfuse/langfuse_otel.py | 8 +++---- .../integrations/test_langfuse_otel.py | 23 +++++++++++-------- .../test_callback_config_validation.py | 4 ---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/litellm/integrations/langfuse/langfuse_otel.py b/litellm/integrations/langfuse/langfuse_otel.py index 70a54223204..29909b85e31 100644 --- a/litellm/integrations/langfuse/langfuse_otel.py +++ b/litellm/integrations/langfuse/langfuse_otel.py @@ -226,10 +226,10 @@ class LangfuseOtelLogger(OpenTelemetry): from litellm.integrations.arize._utils import safe_set_attribute from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - dynamic_params: Final = kwargs.get("standard_callback_dynamic_params") or {} - langfuse_environment: Final = dynamic_params.get("langfuse_environment") or os.environ.get( - "LANGFUSE_TRACING_ENVIRONMENT" - ) + dynamic_params: Final = kwargs.get("standard_callback_dynamic_params") + langfuse_environment: Final = ( + dynamic_params.get("langfuse_environment") if dynamic_params else None + ) or os.environ.get("LANGFUSE_TRACING_ENVIRONMENT") if langfuse_environment: safe_set_attribute( span, diff --git a/tests/test_litellm/integrations/test_langfuse_otel.py b/tests/test_litellm/integrations/test_langfuse_otel.py index 3b5e0c1ae33..7d71d5870e6 100644 --- a/tests/test_litellm/integrations/test_langfuse_otel.py +++ b/tests/test_litellm/integrations/test_langfuse_otel.py @@ -139,7 +139,15 @@ class TestLangfuseOtelIntegration: def test_set_langfuse_environment_attribute_prefers_dynamic_param(self): """Per-key/team langfuse_environment beats the deployment env var.""" - mock_span = MagicMock() + + class _RecordingSpan: + def __init__(self): + self.attributes = {} + + def set_attribute(self, key, value): + self.attributes[key] = value + + span = _RecordingSpan() mock_kwargs = { "standard_callback_dynamic_params": { "langfuse_environment": "team-a-env" @@ -149,16 +157,11 @@ class TestLangfuseOtelIntegration: with patch.dict( os.environ, {"LANGFUSE_TRACING_ENVIRONMENT": "deployment-wide"} ): - with patch( - "litellm.integrations.arize._utils.safe_set_attribute" - ) as mock_safe_set_attribute: - LangfuseOtelLogger._set_langfuse_specific_attributes( - mock_span, mock_kwargs, {} - ) + LangfuseOtelLogger._set_langfuse_specific_attributes( + span, mock_kwargs, {} + ) - mock_safe_set_attribute.assert_called_once_with( - mock_span, "langfuse.environment", "team-a-env" - ) + assert span.attributes["langfuse.environment"] == "team-a-env" def test_extract_langfuse_metadata_basic(self): """Ensure metadata is correctly pulled from litellm_params.""" diff --git a/tests/test_litellm/proxy/common_utils/test_callback_config_validation.py b/tests/test_litellm/proxy/common_utils/test_callback_config_validation.py index 2d262db51a1..5a06bb92059 100644 --- a/tests/test_litellm/proxy/common_utils/test_callback_config_validation.py +++ b/tests/test_litellm/proxy/common_utils/test_callback_config_validation.py @@ -4,10 +4,6 @@ from litellm.proxy.common_utils.callback_config_validation import ( def test_callback_config_error_rejects_invalid_langfuse_environment(): - from litellm.proxy.common_utils.callback_config_validation import ( - callback_config_error, - ) - for callback in ["langfuse", "langfuse_otel"]: error = callback_config_error(callback, {"langfuse_environment": "Production"}) assert error is not None and "langfuse_environment" in error