diff --git a/tests/_vcr_redis_persister.py b/tests/_vcr_redis_persister.py index d8cda930983..f9a5ee1aa83 100644 --- a/tests/_vcr_redis_persister.py +++ b/tests/_vcr_redis_persister.py @@ -91,26 +91,13 @@ _PATCHED_AIOHTTP_RECORD = False def patch_vcrpy_aiohttp_record_path() -> None: - """Make vcrpy's aiohttp record path leave the response body re-readable. - - vcrpy.stubs.aiohttp_stubs.record_response calls ``await response.read()`` - to capture the body for the cassette, which drains aiohttp's StreamReader. - Downstream consumers of the same ClientResponse (e.g. - ``litellm.llms.custom_httpx.aiohttp_transport.AiohttpResponseStream``, - which iterates ``response.content.iter_chunked``) then see an empty body - and surface as ``Expecting value: line 1 column 1 (char 0)`` JSON errors. - - Re-feed the captured bytes back into the StreamReader via ``unread_data`` - so the body remains available to whoever holds the ClientResponse next. - Idempotent; safe to call from multiple conftests. - """ + """Re-feed the response body into aiohttp's StreamReader after vcrpy's + record_response drains it, so downstream consumers (e.g. + LiteLLMAiohttpTransport.AiohttpResponseStream) can still read it.""" global _PATCHED_AIOHTTP_RECORD if _PATCHED_AIOHTTP_RECORD: return - try: - import vcr.stubs.aiohttp_stubs as _aiohttp_stubs - except ImportError: # pragma: no cover - aiohttp not installed in env - return + import vcr.stubs.aiohttp_stubs as _aiohttp_stubs _orig_record_response = _aiohttp_stubs.record_response @@ -118,13 +105,7 @@ def patch_vcrpy_aiohttp_record_path() -> None: await _orig_record_response(cassette, vcr_request, response) body = getattr(response, "_body", None) or b"" if body: - try: - response.content.unread_data(body) - except Exception: - # If aiohttp removes unread_data in a future release we want - # the test to fail loudly via the original empty-body - # symptom rather than mask the regression here. - pass + response.content.unread_data(body) _aiohttp_stubs.record_response = _record_response_preserving_body _PATCHED_AIOHTTP_RECORD = True diff --git a/tests/llm_responses_api_testing/conftest.py b/tests/llm_responses_api_testing/conftest.py index 02cc88ee0d9..b58508d5aee 100644 --- a/tests/llm_responses_api_testing/conftest.py +++ b/tests/llm_responses_api_testing/conftest.py @@ -98,9 +98,6 @@ def pytest_recording_configure(config, vcr): if _vcr_disabled(): return vcr.register_persister(make_redis_persister()) - # vcrpy's aiohttp record path drains the response stream via - # ``await response.read()``; without the patch, downstream consumers - # (litellm's AiohttpResponseStream) see an empty body on first record. patch_vcrpy_aiohttp_record_path() diff --git a/tests/llm_translation/conftest.py b/tests/llm_translation/conftest.py index 2d8623b8366..6969b1167d3 100644 --- a/tests/llm_translation/conftest.py +++ b/tests/llm_translation/conftest.py @@ -122,9 +122,6 @@ def pytest_recording_configure(config, vcr): if _vcr_disabled(): return vcr.register_persister(make_redis_persister()) - # vcrpy's aiohttp record path drains the response stream via - # ``await response.read()``; without the patch, downstream consumers - # (litellm's AiohttpResponseStream) see an empty body on first record. patch_vcrpy_aiohttp_record_path() diff --git a/tests/llm_translation/test_anthropic_completion.py b/tests/llm_translation/test_anthropic_completion.py index faff76edb68..2c219282107 100644 --- a/tests/llm_translation/test_anthropic_completion.py +++ b/tests/llm_translation/test_anthropic_completion.py @@ -1888,13 +1888,6 @@ def test_metadata_filter_applies_to_azure_anthropic(): def test_anthropic_basic_completion_replay(): - """Smoke-test the Anthropic completion pipeline end-to-end via VCR. - - Asserts on response shape rather than specific bytes, so the test is - valid both on a fresh CI Redis (records on first run) and on a hot - cache (replays). Drift in the *shape* of Anthropic's response surfaces - here; drift in the exact text/token counts is expected and ignored. - """ response = litellm.completion( model="anthropic/claude-sonnet-4-5-20250929", messages=[{"role": "user", "content": "Hello!"}], @@ -1909,7 +1902,6 @@ def test_anthropic_basic_completion_replay(): def test_anthropic_streaming_completion_replay(): - """Same as above for the streaming path; asserts on shape, not bytes.""" stream = litellm.completion( model="anthropic/claude-sonnet-4-5-20250929", messages=[{"role": "user", "content": "Hello!"}],