File tree Expand file tree Collapse file tree
tests/unit/agentplatform/genai Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717
1818import importlib
1919import pytest
20+ import warnings
2021from unittest import mock
2122
2223from google .cloud import aiplatform
2324import agentplatform
2425from agentplatform ._genai import client as agentplatform_client
2526from google .cloud .aiplatform import initializer as aiplatform_initializer
27+ import vertexai
28+ from vertexai ._genai import client as vertexai_client
2629
2730
2831_TEST_PROJECT = "test-project"
@@ -106,3 +109,16 @@ async def test_call_aclose_async_client(self):
106109 ).aio
107110 await async_client .aclose ()
108111 mock_aclose .assert_called ()
112+
113+ @pytest .mark .usefixtures ("google_auth_mock" )
114+ def test_vertexai_client_deprecation_warning (self ):
115+
116+ with mock .patch .object (vertexai_client , "_CLIENT_WARNING_SHOWN" , False ):
117+ # Assert that the warning is triggered on the first instantiation
118+ with pytest .warns (FutureWarning , match = "The vertexai.Client class is deprecated" ):
119+ _ = vertexai .Client (project = _TEST_PROJECT , location = _TEST_LOCATION )
120+ # Assert that the warning is NOT triggered on subsequent instantiations
121+ with warnings .catch_warnings ():
122+ warnings .simplefilter ("error" , FutureWarning )
123+ _ = vertexai .Client (project = _TEST_PROJECT , location = _TEST_LOCATION )
124+ _ = vertexai .Client (project = _TEST_PROJECT , location = _TEST_LOCATION )
Original file line number Diff line number Diff line change 1616import asyncio
1717import importlib
1818import sys
19+ import warnings
1920from typing import Optional , Union , TYPE_CHECKING
2021from types import TracebackType , ModuleType
2122
4344
4445
4546_GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules"
47+ _CLIENT_WARNING_SHOWN = False
4648
4749
4850def _custom_append_library_version_headers (headers : dict [str , str ]) -> None :
@@ -239,6 +241,14 @@ def __init__(
239241 http_options (Union[HttpOptions, HttpOptionsDict]): Http options to use
240242 for the client.
241243 """
244+ global _CLIENT_WARNING_SHOWN
245+ if not _CLIENT_WARNING_SHOWN :
246+ warnings .warn (
247+ "The vertexai.Client class is deprecated. Please use agentplatform.Client instead." ,
248+ FutureWarning ,
249+ stacklevel = 2 ,
250+ )
251+ _CLIENT_WARNING_SHOWN = True
242252
243253 self ._debug_config = debug_config or genai_client .DebugConfig ()
244254 if isinstance (http_options , dict ):
You can’t perform that action at this time.
0 commit comments