From e4b2f627589a53ca60d063ca0bdf70f72e61984c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 26 Feb 2026 17:58:26 +0000 Subject: [PATCH] test: fix test params and improve get recovery test Co-authored-by: Ishaan Jaff --- .../test_httpx_client_closed_error.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/test_litellm/llms/custom_httpx/test_httpx_client_closed_error.py b/tests/test_litellm/llms/custom_httpx/test_httpx_client_closed_error.py index 6133973c0b4..3828a9c33c0 100644 --- a/tests/test_litellm/llms/custom_httpx/test_httpx_client_closed_error.py +++ b/tests/test_litellm/llms/custom_httpx/test_httpx_client_closed_error.py @@ -166,16 +166,12 @@ class TestGetSyncHttpxClientClosedCheck: try: litellm.in_memory_llm_clients_cache = cache - client_1 = _get_httpx_client( - params={"client_alias": "test_closed_sync"}, - ) + client_1 = _get_httpx_client() client_1.client.close() assert client_1.client.is_closed is True - client_2 = _get_httpx_client( - params={"client_alias": "test_closed_sync"}, - ) + client_2 = _get_httpx_client() assert client_2 is not client_1 assert client_2.client.is_closed is False @@ -217,11 +213,18 @@ class TestAsyncHTTPHandlerClosedClientRecovery: assert handler.client.is_closed is True mock_response = httpx.Response(200, text="ok") - with patch.object( - httpx.AsyncClient, - "get", - return_value=mock_response, - ): + call_count = 0 + + original_get = httpx.AsyncClient.get + + async def side_effect(self_client, *args, **kwargs): + nonlocal call_count + call_count += 1 + if self_client.is_closed: + raise RuntimeError("Cannot send a request, as the client has been closed.") + return mock_response + + with patch.object(httpx.AsyncClient, "get", side_effect): response = await handler.get(url="https://example.com/api") assert response.status_code == 200