mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
Some checks failed
Build uv cache / build-cache (3.10) (push) Has been cancelled
Build uv cache / build-cache (3.11) (push) Has been cancelled
Build uv cache / build-cache (3.12) (push) Has been cancelled
Build uv cache / build-cache (3.13) (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Notify Downstream / notify-downstream (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Consolidates pytest config, standardizes env handling, reorganizes cassette layout, removes outdated VCR configs, improves sync with threading.Condition, updates event-waiting logic, ensures cleanup, regenerates Gemini cassettes, and reverts unintended test changes.
113 lines
3.7 KiB
Python
113 lines
3.7 KiB
Python
"""Tests to verify that traces are sent when enabled and not sent when disabled.
|
|
|
|
VCR will record HTTP interactions. Inspect cassettes to verify tracing behavior.
|
|
"""
|
|
|
|
import pytest
|
|
from crewai import Agent, Crew, Task
|
|
from tests.utils import wait_for_event_handlers
|
|
|
|
|
|
class TestTraceEnableDisable:
|
|
"""Test suite to verify trace sending behavior with VCR cassette recording."""
|
|
|
|
@pytest.mark.vcr()
|
|
def test_no_http_calls_when_disabled_via_env(self):
|
|
"""Test execution when tracing disabled via CREWAI_TRACING_ENABLED=false."""
|
|
with pytest.MonkeyPatch.context() as mp:
|
|
mp.setenv("CREWAI_TRACING_ENABLED", "false")
|
|
mp.setenv("CREWAI_DISABLE_TELEMETRY", "false")
|
|
|
|
agent = Agent(
|
|
role="Test Agent",
|
|
goal="Test goal",
|
|
backstory="Test backstory",
|
|
llm="gpt-4o-mini",
|
|
)
|
|
task = Task(
|
|
description="Say hello",
|
|
expected_output="hello",
|
|
agent=agent,
|
|
)
|
|
crew = Crew(agents=[agent], tasks=[task], verbose=False)
|
|
|
|
result = crew.kickoff()
|
|
wait_for_event_handlers()
|
|
|
|
assert result is not None
|
|
|
|
@pytest.mark.vcr()
|
|
def test_no_http_calls_when_disabled_via_tracing_false(self):
|
|
"""Test execution when tracing=False explicitly set."""
|
|
with pytest.MonkeyPatch.context() as mp:
|
|
mp.setenv("CREWAI_DISABLE_TELEMETRY", "false")
|
|
|
|
agent = Agent(
|
|
role="Test Agent",
|
|
goal="Test goal",
|
|
backstory="Test backstory",
|
|
llm="gpt-4o-mini",
|
|
)
|
|
task = Task(
|
|
description="Say hello",
|
|
expected_output="hello",
|
|
agent=agent,
|
|
)
|
|
crew = Crew(agents=[agent], tasks=[task], verbose=False, tracing=False)
|
|
|
|
result = crew.kickoff()
|
|
wait_for_event_handlers()
|
|
|
|
assert result is not None
|
|
|
|
@pytest.mark.vcr()
|
|
def test_trace_calls_when_enabled_via_env(self):
|
|
"""Test execution when tracing enabled via CREWAI_TRACING_ENABLED=true."""
|
|
with pytest.MonkeyPatch.context() as mp:
|
|
mp.setenv("CREWAI_TRACING_ENABLED", "true")
|
|
mp.setenv("CREWAI_DISABLE_TELEMETRY", "false")
|
|
mp.setenv("OTEL_SDK_DISABLED", "false")
|
|
|
|
agent = Agent(
|
|
role="Test Agent",
|
|
goal="Test goal",
|
|
backstory="Test backstory",
|
|
llm="gpt-4o-mini",
|
|
)
|
|
task = Task(
|
|
description="Say hello",
|
|
expected_output="hello",
|
|
agent=agent,
|
|
)
|
|
crew = Crew(agents=[agent], tasks=[task], verbose=False)
|
|
|
|
result = crew.kickoff()
|
|
wait_for_event_handlers()
|
|
|
|
assert result is not None
|
|
|
|
@pytest.mark.vcr()
|
|
def test_trace_calls_when_enabled_via_tracing_true(self):
|
|
"""Test execution when tracing=True explicitly set."""
|
|
with pytest.MonkeyPatch.context() as mp:
|
|
mp.setenv("CREWAI_DISABLE_TELEMETRY", "false")
|
|
mp.setenv("OTEL_SDK_DISABLED", "false")
|
|
|
|
agent = Agent(
|
|
role="Test Agent",
|
|
goal="Test goal",
|
|
backstory="Test backstory",
|
|
llm="gpt-4o-mini",
|
|
)
|
|
task = Task(
|
|
description="Say hello",
|
|
expected_output="hello",
|
|
agent=agent,
|
|
)
|
|
crew = Crew(agents=[agent], tasks=[task], verbose=False, tracing=True)
|
|
|
|
result = crew.kickoff()
|
|
wait_for_event_handlers()
|
|
|
|
assert result is not None
|