Skip to content

Commit 5712656

Browse files
committed
fix: Separate unit tests and fix asyncio in test_predict\n\n- Separated unit tests into unit and unit-minimal sessions to handle different dependency needs.\n- Added @pytest.mark.asyncio to TestModelServer.test_predict.
1 parent f84e695 commit 5712656

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

noxfile.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
9898
nox.options.sessions = [
9999
"unit",
100+
"unit_minimal",
100101
"unit_ray",
101102
"unit_langchain",
102103
"unit_ag2",
@@ -219,6 +220,7 @@ def default(session):
219220
"--ignore=tests/unit/vertex_ag2",
220221
"--ignore=tests/unit/vertex_llama_index",
221222
"--ignore=tests/unit/architecture",
223+
"--ignore=tests/unit/vertexai/test_generative_models.py", # Exclude minimal tests
222224
os.path.join("tests", "unit"),
223225
*session.posargs,
224226
)
@@ -235,11 +237,7 @@ def default(session):
235237

236238
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
237239
def unit(session):
238-
"""Run the unit test suite."""
239-
# First run the minimal GenAI tests
240-
unit_genai_minimal_dependencies(session)
241-
242-
# Then run the default full test suite
240+
"""Run the default unit test suite."""
243241
default(session)
244242

245243

@@ -254,14 +252,18 @@ def unit_genai_minimal_dependencies(session):
254252
session.run(
255253
"py.test",
256254
"--quiet",
257-
f"--junitxml=unit_{session.python}_sponge_log.xml",
258-
# These tests require the PIL module
259-
# "--ignore=TestGenerativeModels::test_image_mime_types",
255+
f"--junitxml=unit_minimal_{session.python}_sponge_log.xml",
260256
os.path.join("tests", "unit", "vertexai", "test_generative_models.py"),
261257
*session.posargs,
262258
)
263259

264260

261+
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
262+
def unit_minimal(session):
263+
"""Run the minimal GenAI unit tests."""
264+
unit_genai_minimal_dependencies(session)
265+
266+
265267
@nox.session(python=["3.10", "3.11"])
266268
@nox.parametrize("ray", ["2.9.3", "2.33.0", "2.42.0", "2.47.1"])
267269
def unit_ray(session, ray):

tests/unit/aiplatform/test_prediction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3279,6 +3279,7 @@ def test_init_no_aip_predict_route(
32793279

32803280
assert str(exception.value) == expected_message
32813281

3282+
32823283
def test_health(self, model_server_env_mock, importlib_import_module_mock_twice):
32833284
model_server = CprModelServer()
32843285
client = TestClient(model_server.app)
@@ -3287,10 +3288,12 @@ def test_health(self, model_server_env_mock, importlib_import_module_mock_twice)
32873288

32883289
assert response.status_code == 200
32893290

3290-
def test_predict(self, model_server_env_mock, importlib_import_module_mock_twice):
3291+
@pytest.mark.asyncio
3292+
async def test_predict(self, model_server_env_mock, importlib_import_module_mock_twice):
32913293
model_server = CprModelServer()
32923294
client = TestClient(model_server.app)
32933295

3296+
32943297
with mock.patch.object(model_server.handler, "handle") as handle_mock:
32953298
future = asyncio.Future()
32963299
future.set_result(Response())

0 commit comments

Comments
 (0)