From 90489a481c4bdd92e2c213f794171fce620e1fc3 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Sun, 15 Feb 2026 13:41:29 -0300 Subject: [PATCH] refactor: remove dead code from test cleanup per greptile feedback Removes hasattr checks for non-existent attributes _langfuse_clients and _langfuse_client_cache as identified by greptile code review. Changes: - Remove hasattr check for LangFuseLogger._langfuse_clients (doesn't exist) - Remove hasattr check for self.logger._langfuse_client_cache (doesn't exist) - Keep only the effective cleanup: self.logger.Langfuse = None and del self.logger The core fix (nulling Langfuse reference and deleting logger instance) remains unchanged and effective. This just removes dead code that was misleading. Addresses: https://github.com/BerriAI/litellm/pull/21248#issuecomment Co-Authored-By: Claude Sonnet 4.5 --- tests/test_litellm/integrations/test_langfuse.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/test_litellm/integrations/test_langfuse.py b/tests/test_litellm/integrations/test_langfuse.py index 20e551479c9..15f252a4afc 100644 --- a/tests/test_litellm/integrations/test_langfuse.py +++ b/tests/test_litellm/integrations/test_langfuse.py @@ -77,19 +77,12 @@ class TestLangfuseUsageDetails(unittest.TestCase): sys.modules["langfuse"].Langfuse = self.mock_langfuse_class # Create a fresh logger instance for each test - # Force a clean state by clearing any class-level cached state - if hasattr(LangFuseLogger, '_langfuse_clients'): - LangFuseLogger._langfuse_clients = {} - self.logger = LangFuseLogger() # Explicitly set the Langfuse client to our mock self.logger.Langfuse = self.mock_langfuse_client # Ensure langfuse_sdk_version is set correctly for _supports_* methods self.logger.langfuse_sdk_version = "3.0.0" - # Reset any cached client instances - if hasattr(self.logger, '_langfuse_client_cache'): - self.logger._langfuse_client_cache = None # Add the log_event_on_langfuse method to the instance def log_event_on_langfuse( @@ -132,11 +125,9 @@ class TestLangfuseUsageDetails(unittest.TestCase): def tearDown(self): # Clean up logger instance to prevent state leakage if hasattr(self, 'logger'): - # Reset logger's Langfuse client + # Reset logger's Langfuse client to break any references self.logger.Langfuse = None - # Clear any cached state - if hasattr(self.logger, '_langfuse_client_cache'): - self.logger._langfuse_client_cache = None + # Delete logger instance to ensure complete cleanup del self.logger self.env_patcher.stop()