Skip to content

Commit 0f805b5

Browse files
committed
Use pytest.importorskip for Vertex AI tests & remove vertex_ai_skip helper
1 parent d64c214 commit 0f805b5

7 files changed

Lines changed: 12 additions & 68 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from apache_beam.io.filesystems import FileSystems
2828
from apache_beam.ml.inference.base import RunInference
2929
from apache_beam.testing.test_pipeline import TestPipeline
30-
from apache_beam.testing.vertex_ai_skip import skip_if_vertex_ai_disabled
30+
31+
pytest.importorskip("vertexai", reason="Vertex AI dependencies not available")
3132

3233
# pylint: disable=ungrouped-imports
3334
try:
@@ -54,7 +55,6 @@
5455
_INVOKE_OUTPUT_DIR = "gs://apache-beam-ml/testing/outputs/vertex_invoke"
5556

5657

57-
@skip_if_vertex_ai_disabled
5858
@pytest.mark.vertex_ai_postcommit
5959
class VertexAIInference(unittest.TestCase):
6060
def test_vertex_ai_run_flower_image_classification(self):

sdks/python/apache_beam/ml/rag/embeddings/vertex_ai_test.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from apache_beam.testing.test_pipeline import TestPipeline
3535
from apache_beam.testing.util import assert_that
3636
from 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
4041
try:
@@ -43,9 +44,10 @@
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
4747
except 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

5153
def 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")
6767
class 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")
122120
class 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")
157152
class VertexAIImageEmbeddingsTest(unittest.TestCase):
158153
def setUp(self):
159154
self.artifact_location = tempfile.mkdtemp(prefix='vertex_ai_img_')

sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_test.py renamed to sdks/python/apache_beam/ml/transforms/embeddings/vertex_ai_it_test.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from apache_beam.ml.inference.base import RunInference
2727
from apache_beam.ml.transforms import base
2828
from apache_beam.ml.transforms.base import MLTransform
29-
from apache_beam.testing.vertex_ai_skip import skip_if_vertex_ai_disabled
29+
30+
pytest.importorskip("vertexai", reason="Vertex AI dependencies not available")
3031

3132
# pylint: disable=ungrouped-imports
3233
# isort: off
@@ -61,10 +62,7 @@
6162
model_name: str = "text-embedding-005"
6263

6364

64-
@skip_if_vertex_ai_disabled
6565
@pytest.mark.vertex_ai_postcommit
66-
@unittest.skipIf(
67-
VertexAITextEmbeddings is None, 'Vertex AI Python SDK is not installed.')
6866
class VertexAIEmbeddingsTest(unittest.TestCase):
6967
def setUp(self) -> None:
7068
self.artifact_location = tempfile.mkdtemp(prefix='_vertex_ai_test')
@@ -266,9 +264,7 @@ def test_mltransform_to_ptransform_with_vertex(self):
266264
ptransform_list[i]._model_handler._underlying.model_name, model_name)
267265

268266

269-
@skip_if_vertex_ai_disabled
270-
@unittest.skipIf(
271-
VertexAIImageEmbeddings is None, 'Vertex AI Python SDK is not installed.')
267+
@pytest.mark.vertex_ai_postcommit
272268
class VertexAIImageEmbeddingsTest(unittest.TestCase):
273269
def setUp(self) -> None:
274270
self.artifact_location = tempfile.mkdtemp(prefix='_vertex_ai_image_test')
@@ -314,11 +310,7 @@ def _make_text_chunk(input: str) -> Chunk:
314310
return Chunk(content=Content(text=input))
315311

316312

317-
@skip_if_vertex_ai_disabled
318313
@pytest.mark.vertex_ai_postcommit
319-
@unittest.skipIf(
320-
VertexAIMultiModalEmbeddings is None,
321-
'Vertex AI Python SDK is not installed.')
322314
class VertexAIMultiModalEmbeddingsTest(unittest.TestCase):
323315
def setUp(self) -> None:
324316
self.artifact_location = tempfile.mkdtemp(

sdks/python/apache_beam/testing/vertex_ai_skip.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

sdks/python/test-suites/dataflow/common.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ task vertexAIInferenceTest {
504504
def cmdArgs = mapToArgString(argMap)
505505
exec {
506506
executable 'sh'
507-
args '-c', ". ${envdir}/bin/activate && RUN_VERTEX_AI_TESTS=1 ${runScriptsDir}/run_integration_test.sh $cmdArgs"
507+
args '-c', ". ${envdir}/bin/activate && ${runScriptsDir}/run_integration_test.sh $cmdArgs"
508508
}
509509
}
510510
}

sdks/python/test-suites/tox/py310/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ toxTask "testPy310transformers-447", "py310-transformers-447", "${posargs}"
159159
test.dependsOn "testPy310transformers-447"
160160
postCommitPyDep.dependsOn "testPy310transformers-447"
161161

162-
toxTask "testPy310transformers-448", "py310-transformers-448", "${posargs}"
163-
test.dependsOn "testPy310transformers-448"
164-
postCommitPyDep.dependsOn "testPy310transformers-448"
165-
166162
toxTask "testPy310transformers-latest", "py310-transformers-latest", "${posargs}"
167163
test.dependsOn "testPy310transformers-latest"
168164
postCommitPyDep.dependsOn "testPy310transformers-latest"

sdks/python/tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ commands =
512512
# Allow exit code 5 (no tests run) so that we can run this command safely on arbitrary subdirectories.
513513
/bin/sh -c 'pytest -o junit_suite_name={envname} --junitxml=pytest_{envname}.xml -n 6 -m uses_xgboost {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
514514

515-
[testenv:py{310,311}-transformers-{428,447,448,latest}]
515+
[testenv:py{310,311}-transformers-{428,447,latest}]
516516
deps =
517517
# Environment dependencies are defined in the `setenv` section and installed in the `commands` section.
518518
pip_pre = False
@@ -522,7 +522,6 @@ setenv =
522522
# sentence-transformers 2.2.2 is the latest version that supports transformers 4.28.x
523523
428: DEPS = sentence-transformers==2.2.2 'transformers>=4.28.0,<4.29.0' 'torch>=1.9.0,<1.14.0'
524524
447: DEPS = 'transformers>=4.47.0,<4.48.0' 'torch>=1.9.0,<1.14.0'
525-
448: DEPS = 'transformers>=4.48.0,<4.49.0' 'torch>=1.9.0,<1.14.0'
526525
latest: DEPS = 'transformers>=4.55.0' 'torch>=2.0.0' 'accelerate>=1.6.0'
527526
commands =
528527
/bin/sh -c "pip install .[{extras}] {env:DEPS} {env:COMMON_DEPS}"

0 commit comments

Comments
 (0)