3434from apache_beam .testing .test_pipeline import TestPipeline
3535from apache_beam .testing .util import assert_that
3636from apache_beam .testing .util import equal_to
37- from apache_beam .testing .vertex_ai_skip import skip_if_vertex_ai_disabled
37+
38+ pytest .importorskip ("vertexai" , reason = "Vertex AI dependencies not available" )
3839
3940# pylint: disable=ungrouped-imports
4041try :
4344 from apache_beam .ml .rag .embeddings .vertex_ai import VertexAIImageEmbeddings
4445 from apache_beam .ml .rag .embeddings .vertex_ai import VertexAITextEmbeddings
4546 from apache_beam .ml .rag .embeddings .vertex_ai import _create_image_adapter
46- VERTEX_AI_AVAILABLE = True
4747except ImportError :
48- VERTEX_AI_AVAILABLE = False
48+ VertexAIImageEmbeddings = None # type: ignore
49+ VertexAITextEmbeddings = None # type: ignore
50+ _create_image_adapter = None # type: ignore
4951
5052
5153def chunk_approximately_equals (expected , actual ):
@@ -62,8 +64,6 @@ def chunk_approximately_equals(expected, actual):
6264
6365
6466@pytest .mark .vertex_ai_postcommit
65- @unittest .skipIf (
66- not VERTEX_AI_AVAILABLE , "Vertex AI dependencies not available" )
6767class VertexAITextEmbeddingsTest (unittest .TestCase ):
6868 def setUp (self ):
6969 self .artifact_location = tempfile .mkdtemp (prefix = 'vertex_ai_' )
@@ -117,8 +117,6 @@ def test_embedding_pipeline(self):
117117 embeddings , equal_to (expected , equals_fn = chunk_approximately_equals ))
118118
119119
120- @unittest .skipIf (
121- not VERTEX_AI_AVAILABLE , "Vertex AI dependencies not available" )
122120class VertexAIImageAdapterTest (unittest .TestCase ):
123121 def test_image_adapter_missing_content (self ):
124122 adapter = _create_image_adapter ()
@@ -150,10 +148,7 @@ def test_image_adapter_output(self):
150148 self .assertEqual (result [0 ].embedding .dense_embedding , [0.1 , 0.2 , 0.3 ])
151149
152150
153- @skip_if_vertex_ai_disabled
154151@pytest .mark .vertex_ai_postcommit
155- @unittest .skipIf (
156- not VERTEX_AI_AVAILABLE , "Vertex AI dependencies not available" )
157152class VertexAIImageEmbeddingsTest (unittest .TestCase ):
158153 def setUp (self ):
159154 self .artifact_location = tempfile .mkdtemp (prefix = 'vertex_ai_img_' )
0 commit comments