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 <noreply@anthropic.com>
This commit is contained in:
Julio Quinteros Pro 2026-02-15 13:45:23 -03:00
parent c362804872
commit 4c53ccd90d

View file

@ -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()