chore: restructure test env, cassettes, and conftest; fix flaky tests
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.
This commit is contained in:
Greyson LaLonde
2025-11-29 16:55:24 -05:00
committed by GitHub
parent bc4e6a3127
commit c925d2d519
200 changed files with 2070 additions and 1891 deletions

View File

@@ -11,7 +11,7 @@ from tests.utils import wait_for_event_handlers
class TestTraceEnableDisable:
"""Test suite to verify trace sending behavior with VCR cassette recording."""
@pytest.mark.vcr(filter_headers=["authorization"])
@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:
@@ -36,7 +36,7 @@ class TestTraceEnableDisable:
assert result is not None
@pytest.mark.vcr(filter_headers=["authorization"])
@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:
@@ -60,7 +60,7 @@ class TestTraceEnableDisable:
assert result is not None
@pytest.mark.vcr(filter_headers=["authorization"])
@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:
@@ -86,7 +86,7 @@ class TestTraceEnableDisable:
assert result is not None
@pytest.mark.vcr(filter_headers=["authorization"])
@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:

View File

@@ -154,7 +154,7 @@ class TestTraceListenerSetup:
"mark_trace_batch_as_failed": mock_mark_failed,
}
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_trace_listener_collects_crew_events(self):
"""Test that trace listener properly collects events from crew execution"""
@@ -191,7 +191,7 @@ class TestTraceListenerSetup:
assert trace_listener.batch_manager.is_batch_initialized()
assert trace_listener.batch_manager.current_batch is not None
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_batch_manager_finalizes_batch_clears_buffer(self):
"""Test that batch manager properly finalizes batch and clears buffer"""
@@ -257,7 +257,7 @@ class TestTraceListenerSetup:
assert finalize_mock.call_count >= 1
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_events_collection_batch_manager(self, mock_plus_api_calls):
"""Test that trace listener properly collects events from crew execution"""
@@ -318,7 +318,7 @@ class TestTraceListenerSetup:
assert hasattr(event, "event_data")
assert hasattr(event, "type")
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_trace_listener_disabled_when_env_false(self):
"""Test that trace listener doesn't make HTTP calls when tracing is disabled"""
@@ -389,7 +389,7 @@ class TestTraceListenerSetup:
Crew(agents=[agent], tasks=[task], verbose=True)
assert mock_listener_setup.call_count >= 1
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_trace_listener_setup_correctly_for_flow(self):
"""Test that trace listener is set up correctly when enabled"""
@@ -413,7 +413,7 @@ class TestTraceListenerSetup:
FlowExample()
assert mock_listener_setup.call_count >= 1
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_trace_listener_ephemeral_batch(self):
"""Test that trace listener properly handles ephemeral batches"""
with (
@@ -449,13 +449,14 @@ class TestTraceListenerSetup:
crew.kickoff()
wait_for_event_handlers()
assert trace_listener.batch_manager.is_batch_initialized(), (
initialized = trace_listener.batch_manager.wait_for_batch_initialization(timeout=5.0)
assert initialized, (
"Batch should have been initialized for unauthenticated user"
)
@pytest.mark.vcr(filter_headers=["authorization"])
wait_for_event_handlers()
@pytest.mark.vcr()
def test_trace_listener_with_authenticated_user(self):
"""Test that trace listener properly handles authenticated batches"""
with patch.dict(
@@ -485,12 +486,13 @@ class TestTraceListenerSetup:
crew = Crew(agents=[agent], tasks=[task], tracing=True)
crew.kickoff()
wait_for_event_handlers()
assert trace_listener.batch_manager.is_batch_initialized(), (
initialized = trace_listener.batch_manager.wait_for_batch_initialization(timeout=5.0)
assert initialized, (
"Batch should have been initialized for authenticated user"
)
wait_for_event_handlers()
# Helper method to ensure cleanup
def teardown_method(self):
"""Cleanup after each test method"""
@@ -523,7 +525,7 @@ class TestTraceListenerSetup:
if hasattr(EventListener, "_instance"):
EventListener._instance = None
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_first_time_user_trace_collection_with_timeout(self, mock_plus_api_calls):
"""Test first-time user trace collection logic with timeout behavior"""
@@ -596,7 +598,7 @@ class TestTraceListenerSetup:
mock_mark_completed.assert_called_once()
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_first_time_user_trace_collection_user_accepts(self, mock_plus_api_calls):
"""Test first-time user trace collection when user accepts viewing traces"""
@@ -657,6 +659,10 @@ class TestTraceListenerSetup:
"https://crewai.com/trace/mock-id"
)
assert trace_listener.first_time_handler.is_first_time is True
trace_listener.first_time_handler.collected_events = True
with (
patch.object(
trace_listener.first_time_handler,
@@ -667,22 +673,16 @@ class TestTraceListenerSetup:
trace_listener.first_time_handler, "_display_ephemeral_trace_link"
) as mock_display_link,
):
assert trace_listener.first_time_handler.is_first_time is True
trace_listener.first_time_handler.collected_events = True
crew.kickoff()
wait_for_event_handlers()
trace_listener.first_time_handler.handle_execution_completion()
mock_init_backend.assert_called_once()
mock_display_link.assert_called_once()
mock_mark_completed.assert_called_once()
mock_mark_completed.assert_called_once()
@pytest.mark.vcr(filter_headers=["authorization"])
@pytest.mark.vcr()
def test_first_time_user_trace_consolidation_logic(self, mock_plus_api_calls):
"""Test the consolidation logic for first-time users vs regular tracing"""
with (