mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user