From 4c53ccd90dc689703505ad393f45bf862c42ba46 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Sun, 15 Feb 2026 13:45:23 -0300 Subject: [PATCH] refactor: remove dead code from Langfuse test cleanup Follow-up to PR #21248 addressing greptile code review feedback. Removes hasattr checks for non-existent attributes that were identified as dead code by greptile automated code review. Changes: - Remove hasattr check for LangFuseLogger._langfuse_clients (class attribute doesn't exist) - Remove hasattr check for self.logger._langfuse_client_cache (instance attribute doesn't exist) - Update comments to be more accurate about what cleanup is being done The core fix from PR #21248 (nulling Langfuse reference and deleting logger instance) remains unchanged and effective. This just removes misleading dead code that serves no purpose. Context: These checks were added defensively but reference attributes that don't actually exist on the LangFuseLogger class, making them always no-ops. Greptile correctly identified these as dead code in PR #21248 review, but the PR was merged before the cleanup could be applied. Related: #21248 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 20e551479c..15f252a4af 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()