Skip to content

Commit a1c1bfd

Browse files
committed
test: mock aiplatform.init in VertexAI inference tests to prevent global state pollution.
1 parent a6ffe29 commit a1c1bfd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sdks/python/apache_beam/ml/inference/vertex_ai_inference_test.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ class ParseInvokeResponseTest(unittest.TestCase):
5353
def _create_handler_with_invoke_route(self, invoke_route="/test"):
5454
"""Creates a mock handler with invoke_route for testing."""
5555
import unittest.mock as mock
56+
# Mock both _retrieve_endpoint and aiplatform.init to prevent test
57+
# pollution of global aiplatform state
5658
with mock.patch.object(VertexAIModelHandlerJSON,
5759
'_retrieve_endpoint',
5860
return_value=None):
59-
handler = VertexAIModelHandlerJSON(
60-
endpoint_id="1",
61-
project="testproject",
62-
location="us-central1",
63-
invoke_route=invoke_route)
61+
with mock.patch('google.cloud.aiplatform.init'):
62+
handler = VertexAIModelHandlerJSON(
63+
endpoint_id="1",
64+
project="testproject",
65+
location="us-central1",
66+
invoke_route=invoke_route)
6467
return handler
6568

6669
def test_parse_invoke_response_with_predictions_key(self):

0 commit comments

Comments
 (0)