From a82bc4d239ad544aceb2eb7a7a130f6996c8d2fd Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:46:46 -0700 Subject: [PATCH] test: inject the SDK's own transport in the sync batch list test so it passes on OpenAI SDK 3.x --- tests/unit/llms/openai/test_openai.py | 63 ++++++++++++++------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/tests/unit/llms/openai/test_openai.py b/tests/unit/llms/openai/test_openai.py index 019163aa7b1..230f448a784 100644 --- a/tests/unit/llms/openai/test_openai.py +++ b/tests/unit/llms/openai/test_openai.py @@ -2053,36 +2053,39 @@ def test_openai_config_hoists_a_later_developer_message_only_for_a_model_off_ope @pytest.mark.asyncio async def test_sync_batch_list_given_an_async_client_returns_a_page_the_caller_can_await( - respx_mock: respx.MockRouter, + http_backend: ModuleType, ): - respx_mock.get("http://vllm-router.test/v1/batches").respond( - 200, - json={ - "object": "list", - "data": [ - { - "id": "batch_5f8dac", - "status": "pending", - "input_file_id": "file-b73f4c", - "created_at": 1793239207, - "endpoint": "/v1/chat/completions", - "completion_window": "24h", - } - ], - "first_id": "batch_5f8dac", - "last_id": "batch_5f8dac", - "has_more": False, - }, - ) + def respond(request: _Request) -> httpx.Response | SDKResponse: + assert str(request.url).startswith("http://vllm-router.test/v1/batches") + return http_backend.Response( + 200, + json={ + "object": "list", + "data": [ + { + "id": "batch_5f8dac", + "status": "pending", + "input_file_id": "file-b73f4c", + "created_at": 1793239207, + "endpoint": "/v1/chat/completions", + "completion_window": "24h", + } + ], + "first_id": "batch_5f8dac", + "last_id": "batch_5f8dac", + "has_more": False, + }, + ) - page: Final = OpenAIBatchesAPI().list_batches( - _is_async=False, - api_key="sk-test", - api_base="http://vllm-router.test/v1", - timeout=5.0, - max_retries=0, - organization=None, - client=AsyncOpenAI(api_key="sk-test", base_url="http://vllm-router.test/v1"), - ) + async with http_backend.AsyncClient(transport=http_backend.MockTransport(respond)) as http_client: + page: Final = OpenAIBatchesAPI().list_batches( + _is_async=False, + api_key="sk-test", + api_base="http://vllm-router.test/v1", + timeout=5.0, + max_retries=0, + organization=None, + client=AsyncOpenAI(api_key="sk-test", base_url="http://vllm-router.test/v1", http_client=http_client), + ) - assert [(batch.id, batch.status) for batch in (await page).data] == [("batch_5f8dac", "pending")] + assert [(batch.id, batch.status) for batch in (await page).data] == [("batch_5f8dac", "pending")]