From 0344f74755cf5496ec514b31aa9a65905e6d9dd6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Jun 2026 20:28:25 +0000 Subject: [PATCH] Fix test isolation: reset TraceCollectionListener singleton in cleanup_event_handlers fixture Prevents singleton state pollution (trace_batch_id="debug-trace-batch") from test_flow_conversation.py leaking into test_trace_enable_disable.py when both files run in the same pytest-xdist worker under --dist=loadfile. The polluted singleton caused a background HTTP request to fake.crewai.com that corrupted VCR cassette state, preventing the OpenAI LLM entry from matching. --- conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/conftest.py b/conftest.py index 27bf03a86..f62474de3 100644 --- a/conftest.py +++ b/conftest.py @@ -197,6 +197,21 @@ def cleanup_event_handlers() -> Generator[None, Any, None]: except Exception: # noqa: S110 pass + try: + from crewai.events.listeners.tracing.trace_listener import ( + TraceCollectionListener, + ) + + if TraceCollectionListener._instance is not None: + instance_dict = TraceCollectionListener._instance.__dict__ + if "_initialized" in instance_dict: + del TraceCollectionListener._instance._initialized + if "_listeners_setup" in instance_dict: + del TraceCollectionListener._instance._listeners_setup + TraceCollectionListener._instance = None + except Exception: # noqa: S110 + pass + @pytest.fixture(autouse=True, scope="function") def reset_event_state() -> None: