From daefea040fdb7ce7fc62f500788a55f551e7c8de Mon Sep 17 00:00:00 2001 From: Tommaso Bolis Date: Sun, 25 Oct 2026 20:26:03 +0100 Subject: [PATCH] test: turn off CrewAI telemetry for the suite (#1202) CrewAI exports anonymous telemetry from a background thread. Under the dead ALL_PROXY in test_transport_proxy_mounts.py, that export opened a socket while no_sockets patches socket.connect process-wide. The lowest-direct (crewai) nightly leg then failed on CrewAI's traffic, not ours, whenever the export landed inside a test's window. conftest now sets CREWAI_DISABLE_TELEMETRY=true at load, next to the LiteLLM cost-map switch. The switch is honoured by crewai 1.15.3 (the floor) through 1.15.23. OTEL_SDK_DISABLED would also work but is cleared per test with the other OTEL_* vars. A guard test fails if CrewAI stops honouring the switch. Co-Authored-By: Claude Opus 5.5 (1M context) --- python/tests/conftest.py | 7 +++++++ python/tests/unit/test_transport_proxy_mounts.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 310b2641..008063e1 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -68,6 +68,13 @@ # copy bundled in the wheel instead. It is read once at import, so it is set # here at conftest load, before any test can import litellm. os.environ.setdefault("LITELLM_LOCAL_MODEL_COST_MAP", "True") +# CrewAI exports anonymous usage telemetry from a background thread. Under a +# test's dead proxy that thread opens a socket while ``no_sockets`` patches +# ``socket.connect`` process-wide, so an offline-seam test failed on CrewAI's +# traffic, not ours, whenever the export landed in its window (#1202). +# ``OTEL_SDK_DISABLED`` would also work but is cleared per test with the other +# ``OTEL_*`` vars; this switch is CrewAI's own and is read on every export. +os.environ.setdefault("CREWAI_DISABLE_TELEMETRY", "true") def pytest_collection_modifyitems(items: list[pytest.Item]) -> None: diff --git a/python/tests/unit/test_transport_proxy_mounts.py b/python/tests/unit/test_transport_proxy_mounts.py index b32bde2d..bd3be5fa 100644 --- a/python/tests/unit/test_transport_proxy_mounts.py +++ b/python/tests/unit/test_transport_proxy_mounts.py @@ -209,3 +209,11 @@ def test_swap_refuses_when_a_mount_could_bypass_it(make: object) -> None: client._mounts = {URLPattern("all://"): httpx.MockTransport(lambda r: httpx.Response(200))} with pytest.raises(RuntimeError, match="mounts that would bypass it"): client.governed_transport.replace_inner(httpx.MockTransport(lambda r: httpx.Response(200))) + + +def test_crewai_telemetry_is_off_for_the_suite() -> None: + """``no_sockets`` patches ``socket.connect`` process-wide, so CrewAI's + background telemetry export failed these tests at random (#1202). The + conftest switch turns it off; this fails if CrewAI stops honouring it.""" + telemetry = pytest.importorskip("crewai.telemetry.telemetry") + assert telemetry.Telemetry._is_telemetry_disabled()