tests(vcr): force pure-httpx transport when VCR is active

litellm's default LiteLLMAiohttpTransport routes requests through aiohttp,
which sits below httpx and is invisible to vcrpy's httpx-stub interception.
Under vcrpy + aiohttp, requests reach the real network but responses come
back through the stubbed httpx transport as empty 200s, surfacing as
'Unable to get json response - Expecting value: line 1 column 1 (char 0)'
in providers like Anthropic, Gemini, and any other path that exercises the
aiohttp transport.

Disabling the aiohttp transport when the VCR persister is registered
forces all calls through pure httpx, which vcrpy can record and replay
correctly.
This commit is contained in:
mateo-berri 2026-04-30 17:42:17 -07:00
parent 68db1c5e9e
commit 265a94cd60
2 changed files with 10 additions and 0 deletions

View file

@ -97,6 +97,11 @@ def pytest_recording_configure(config, vcr):
if _vcr_disabled():
return
vcr.register_persister(make_redis_persister())
# vcrpy patches httpx's transport; litellm's default AiohttpTransport
# routes around httpx and produces empty responses under the patched
# transport. Force pure-httpx transport so vcrpy can record/replay.
litellm.disable_aiohttp_transport = True
os.environ["DISABLE_AIOHTTP_TRANSPORT"] = "True"
@pytest.fixture(scope="session")

View file

@ -121,6 +121,11 @@ def pytest_recording_configure(config, vcr):
if _vcr_disabled():
return
vcr.register_persister(make_redis_persister())
# vcrpy patches httpx's transport; litellm's default AiohttpTransport
# routes around httpx and produces empty responses under the patched
# transport. Force pure-httpx transport so vcrpy can record/replay.
litellm.disable_aiohttp_transport = True
os.environ["DISABLE_AIOHTTP_TRANSPORT"] = "True"
# ---------------------------------------------------------------------------