Skip to content

Commit 58f1294

Browse files
Ark-kuncopybara-github
authored andcommitted
chore: Added minimal dependencies unit tests where extra dependencies are not installed
PiperOrigin-RevId: 671515674
1 parent 3446e4e commit 58f1294

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

noxfile.py

+25
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"pytest",
4040
"pytest-cov",
4141
"pytest-asyncio",
42+
# Preventing: py.test: error: unrecognized arguments: -n=auto --dist=loadscope
43+
"pytest-xdist",
4244
]
4345
UNIT_TEST_EXTERNAL_DEPENDENCIES = []
4446
UNIT_TEST_LOCAL_DEPENDENCIES = []
@@ -201,9 +203,32 @@ def default(session):
201203
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
202204
def unit(session):
203205
"""Run the unit test suite."""
206+
# First run the minimal GenAI tests
207+
unit_genai_minimal_dependencies(session)
208+
209+
# Then run the default full test suite
204210
default(session)
205211

206212

213+
def unit_genai_minimal_dependencies(session):
214+
# Install minimal test dependencies, then install this package in-place.
215+
216+
standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
217+
session.install(*standard_deps)
218+
session.install("-e", ".")
219+
220+
# Run py.test against the unit tests.
221+
session.run(
222+
"py.test",
223+
"--quiet",
224+
f"--junitxml=unit_{session.python}_sponge_log.xml",
225+
# These tests require the PIL module
226+
# "--ignore=TestGenerativeModels::test_image_mime_types",
227+
os.path.join("tests", "unit", "vertexai", "test_generative_models.py"),
228+
*session.posargs,
229+
)
230+
231+
207232
@nox.session(python="3.10")
208233
@nox.parametrize("ray", ["2.9.3"])
209234
def unit_ray(session, ray):

tests/unit/vertexai/test_generative_models.py

+1
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,7 @@ def get_current_weather(location: str):
11841184
def test_image_mime_types(
11851185
self, generative_models: generative_models, image_format: str, mime_type: str
11861186
):
1187+
pytest.importorskip("PIL")
11871188
# Importing external library lazily to reduce the scope of import errors.
11881189
from PIL import Image as PIL_Image # pylint: disable=g-import-not-at-top
11891190

0 commit comments

Comments
 (0)