File tree Expand file tree Collapse file tree
google/genai/tests/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616"""Tests for closing the clients and context managers."""
1717import asyncio
1818from unittest import mock
19-
19+ import gc
2020from google .oauth2 import credentials
2121import pytest
2222try :
@@ -194,3 +194,26 @@ async def run():
194194 assert async_client ._api_client ._aiohttp_session .closed
195195
196196 asyncio .run (run ())
197+
198+
199+ def test_partial_init_validation_error_sync_safety ():
200+ """Verifies that BaseApiClient.close() does not crash on a partially initialized client."""
201+
202+ with pytest .raises (ValueError ):
203+ api_client .BaseApiClient (api_key = None , vertexai = False )
204+
205+ # force GC to trigger __del__
206+ gc .collect ()
207+
208+ @pytest .mark .asyncio
209+ async def test_partial_init_validation_error_async_safety ():
210+ """Verifies that BaseApiClient.aclose() does not crash the event loop on a partially initialized client."""
211+
212+ with pytest .raises (ValueError ):
213+ api_client .BaseApiClient (api_key = None , vertexai = False )
214+
215+ # force GC to trigger __del__
216+ gc .collect ()
217+
218+ # make sure the event loop runs to completion
219+ await asyncio .sleep (0 )
You can’t perform that action at this time.
0 commit comments