3636from agentplatform ._genai import runtimes
3737from agentplatform ._genai import types as _genai_types
3838from google .genai import client as genai_client
39+ from google .genai import errors as genai_errors
3940from google .genai import types as genai_types
4041from google .api import httpbody_pb2
4142import pytest
@@ -4154,7 +4155,7 @@ def test_create_runtime_error(
41544155 self .client .runtimes ._api_client , "request"
41554156 ) as request_mock :
41564157 request_mock .return_value = genai_types .HttpResponse (body = "" )
4157- with pytest .raises (RuntimeError ) as excinfo :
4158+ with pytest .raises (genai_errors . APIError ) as excinfo :
41584159 self .client .runtimes .create (
41594160 agent = self .test_agent ,
41604161 config = _genai_types .AgentRuntimeConfig (
@@ -4167,7 +4168,14 @@ def test_create_runtime_error(
41674168 env_vars = _TEST_AGENT_ENGINE_ENV_VARS_INPUT ,
41684169 ),
41694170 )
4170- assert "failed to create Agent Runtime" in str (excinfo .value )
4171+ assert excinfo .value .code == _TEST_AGENT_ENGINE_ERROR ["code" ]
4172+ assert excinfo .value .message == _TEST_AGENT_ENGINE_ERROR ["message" ]
4173+ assert excinfo .value .details == _TEST_AGENT_ENGINE_ERROR
4174+ if sys .version_info >= (3 , 11 ):
4175+ assert any (
4176+ "failed to create Agent Runtime" in note
4177+ for note in excinfo .value .__notes__
4178+ )
41714179
41724180 @mock .patch .object (_runtimes_utils , "_await_operation" )
41734181 def test_update_runtime_description (self , mock_await_operation ):
@@ -4178,14 +4186,21 @@ def test_update_runtime_description(self, mock_await_operation):
41784186 self .client .runtimes ._api_client , "request"
41794187 ) as request_mock :
41804188 request_mock .return_value = genai_types .HttpResponse (body = "" )
4181- with pytest .raises (RuntimeError ) as excinfo :
4189+ with pytest .raises (genai_errors . APIError ) as excinfo :
41824190 self .client .runtimes .update (
41834191 name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
41844192 config = _genai_types .AgentRuntimeConfig (
41854193 description = _TEST_AGENT_ENGINE_DESCRIPTION ,
41864194 ),
41874195 )
4188- assert "failed to update Agent Runtime" in str (excinfo .value )
4196+ assert excinfo .value .code == _TEST_AGENT_ENGINE_ERROR ["code" ]
4197+ assert excinfo .value .message == _TEST_AGENT_ENGINE_ERROR ["message" ]
4198+ assert excinfo .value .details == _TEST_AGENT_ENGINE_ERROR
4199+ if sys .version_info >= (3 , 11 ):
4200+ assert any (
4201+ "failed to update Agent Runtime" in note
4202+ for note in excinfo .value .__notes__
4203+ )
41894204
41904205 @pytest .mark .parametrize (
41914206 "test_case_name, test_operation_schemas, want_log_output" ,
0 commit comments