refactor: remove redundant tests in TestTraceBatchIdClearedOnFailure

Remove test_trace_batch_id_cleared_on_none_response (covered by
  TestInitializeBackendBatchRetry::test_exhausts_retries_then_clears_batch_id)
  and test_trace_batch_id_cleared_on_non_2xx_response (covered by
  TestInitializeBackendBatchRetry::test_no_retry_on_4xx).
This commit is contained in:
Tiago Freire
2026-03-18 20:46:20 -03:00
parent 6734db4f71
commit 7f2eda2ac6

View File

@@ -966,7 +966,7 @@ class TestTraceListenerSetup:
class TestTraceBatchIdClearedOnFailure:
"""Tests for Fix 1: trace_batch_id is cleared when _initialize_backend_batch fails."""
"""Tests: trace_batch_id is cleared when _initialize_backend_batch fails."""
def _make_batch_manager(self):
"""Create a TraceBatchManager with a pre-set trace_batch_id (simulating first-time user)."""
@@ -983,57 +983,6 @@ class TestTraceBatchIdClearedOnFailure:
bm.is_current_batch_ephemeral = True
return bm
def test_trace_batch_id_cleared_on_none_response(self):
"""trace_batch_id must be None when the API returns None."""
bm = self._make_batch_manager()
original_id = bm.trace_batch_id
assert original_id is not None
with (
patch(
"crewai.events.listeners.tracing.trace_batch_manager.is_tracing_enabled_in_context",
return_value=True,
),
patch.object(
bm.plus_api,
"initialize_ephemeral_trace_batch",
return_value=None,
),
):
bm._initialize_backend_batch(
user_context={"privacy_level": "standard"},
execution_metadata={"execution_type": "crew"},
use_ephemeral=True,
)
assert bm.trace_batch_id is None
def test_trace_batch_id_cleared_on_non_2xx_response(self):
"""trace_batch_id must be None when the API returns a non-2xx status."""
bm = self._make_batch_manager()
assert bm.trace_batch_id is not None
mock_response = MagicMock(status_code=422, text="Unprocessable Entity")
with (
patch(
"crewai.events.listeners.tracing.trace_batch_manager.is_tracing_enabled_in_context",
return_value=True,
),
patch.object(
bm.plus_api,
"initialize_ephemeral_trace_batch",
return_value=mock_response,
),
):
bm._initialize_backend_batch(
user_context={"privacy_level": "standard"},
execution_metadata={"execution_type": "crew"},
use_ephemeral=True,
)
assert bm.trace_batch_id is None
def test_trace_batch_id_cleared_on_exception(self):
"""trace_batch_id must be None when the API call raises an exception."""
bm = self._make_batch_manager()
@@ -1270,7 +1219,7 @@ class TestInitializeBackendBatchRetry:
class TestFirstTimeHandlerBackendInitGuard:
"""Tests for Fix 2: backend_initialized gated on actual batch creation success."""
"""Tests: backend_initialized gated on actual batch creation success."""
def _make_handler_with_manager(self):
"""Create a FirstTimeTraceHandler wired to a TraceBatchManager."""