fix: reset telemetry singleton in tests to prevent state persistence on Python 3.10

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-06-18 10:48:17 +00:00
parent c1984e4406
commit 9d09e01800
2 changed files with 9 additions and 0 deletions

View File

@@ -107,6 +107,12 @@ class Telemetry:
cls._instance._initialized = False
return cls._instance
@classmethod
def _reset_instance(cls):
"""Reset the singleton instance for testing purposes."""
with cls._lock:
cls._instance = None
def __init__(self) -> None:
if hasattr(self, '_initialized') and self._initialized:
return

View File

@@ -95,6 +95,9 @@ class TestOptionalDependencies:
def test_opentelemetry_graceful_degradation(self):
"""Test that telemetry degrades gracefully without opentelemetry."""
from crewai.telemetry.telemetry import Telemetry
Telemetry._reset_instance()
with patch.dict('sys.modules', {'opentelemetry': None}):
with patch('crewai.telemetry.telemetry.OPENTELEMETRY_AVAILABLE', False):
from crewai.telemetry.telemetry import Telemetry