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()