Skip to content

Commit a9b153b

Browse files
speedstorm1copybara-github
authored andcommitted
chore: chore
PiperOrigin-RevId: 908911389
1 parent f48e54b commit a9b153b

2 files changed

Lines changed: 89 additions & 32 deletions

File tree

noxfile.py

Lines changed: 88 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"pytest-asyncio",
7070
# Preventing: py.test: error: unrecognized arguments: -n=auto --dist=loadscope
7171
"pytest-xdist",
72+
"pytest-shard",
7273
]
7374
UNIT_TEST_EXTERNAL_DEPENDENCIES = []
7475
UNIT_TEST_LOCAL_DEPENDENCIES = []
@@ -196,41 +197,96 @@ def install_unittest_dependencies(session, *constraints):
196197

197198

198199
def default(session):
199-
# Install all test dependencies, then install this package in-place.
200+
# Install all test dependencies, then install this package in-place.
200201

201-
constraints_path = str(
202+
constraints_path = str(
202203
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
203204
)
204-
install_unittest_dependencies(session, "-c", constraints_path)
205-
206-
# Run py.test against the unit tests.
207-
session.run(
208-
"py.test",
209-
"--quiet",
210-
f"--junitxml=unit_{session.python}_sponge_log.xml",
211-
"--cov=google",
212-
"--cov-append",
213-
"--cov-config=.coveragerc",
214-
"--cov-report=",
215-
"--cov-fail-under=0",
216-
"--ignore=tests/unit/vertex_ray",
217-
"--ignore=tests/unit/vertex_adk",
218-
"--ignore=tests/unit/vertex_langchain",
219-
"--ignore=tests/unit/vertex_ag2",
220-
"--ignore=tests/unit/vertex_llama_index",
221-
"--ignore=tests/unit/architecture",
222-
os.path.join("tests", "unit"),
223-
*session.posargs,
224-
)
225-
226-
# Run tests that require isolation.
227-
session.run(
228-
"py.test",
229-
"--quiet",
230-
f"--junitxml=unit_{session.python}_test_vertexai_import_sponge_log.xml",
231-
os.path.join("tests", "unit", "architecture", "test_vertexai_import.py"),
232-
*session.posargs,
233-
)
205+
install_unittest_dependencies(session, "-c", constraints_path)
206+
207+
ml_framework_tests = [
208+
os.path.join("tests", "unit", "aiplatform", "test_uploader.py"),
209+
os.path.join("tests", "unit", "aiplatform", "test_metadata_models.py"),
210+
os.path.join("tests", "unit", "aiplatform", "test_metadata.py"),
211+
os.path.join("tests", "unit", "aiplatform", "test_logdir_loader.py"),
212+
os.path.join("tests", "unit", "aiplatform", "test_uploader_utils.py"),
213+
os.path.join("tests", "unit", "aiplatform", "test_explain_lit.py"),
214+
os.path.join(
215+
"tests",
216+
"unit",
217+
"aiplatform",
218+
"test_explain_saved_model_metadata_builder_tf1_test.py",
219+
),
220+
os.path.join(
221+
"tests",
222+
"unit",
223+
"aiplatform",
224+
"test_explain_saved_model_metadata_builder_tf2_test.py",
225+
),
226+
]
227+
228+
shard_id = os.environ.get("PYTEST_SHARD_ID")
229+
shard_count = os.environ.get("PYTEST_SHARD_COUNT")
230+
shard_args = []
231+
if shard_id and shard_count:
232+
shard_args = [f"--shard-id={shard_id}", f"--shard-count={shard_count}"]
233+
234+
core_pytest_args = [
235+
"py.test",
236+
"--quiet",
237+
f"--junitxml=unit_core_{session.python}_sponge_log.xml",
238+
"--cov=google",
239+
"--cov-append",
240+
"--cov-config=.coveragerc",
241+
"--cov-report=",
242+
"--cov-fail-under=0",
243+
"--ignore=tests/unit/vertex_ray",
244+
"--ignore=tests/unit/vertex_adk",
245+
"--ignore=tests/unit/vertex_langchain",
246+
"--ignore=tests/unit/vertex_ag2",
247+
"--ignore=tests/unit/vertex_llama_index",
248+
"--ignore=tests/unit/architecture",
249+
]
250+
251+
for ml_test in ml_framework_tests:
252+
core_pytest_args.append(f"--ignore={ml_test}")
253+
254+
core_pytest_args.extend(shard_args)
255+
core_pytest_args.append(os.path.join("tests", "unit"))
256+
core_pytest_args.extend(session.posargs)
257+
258+
# Run py.test against the core unit tests.
259+
session.run(*core_pytest_args)
260+
261+
ml_pytest_args = [
262+
"py.test",
263+
"--quiet",
264+
f"--junitxml=unit_ml_{session.python}_sponge_log.xml",
265+
"--cov=google",
266+
"--cov-append",
267+
"--cov-config=.coveragerc",
268+
"--cov-report=",
269+
"--cov-fail-under=0",
270+
]
271+
272+
ml_pytest_args.extend(shard_args)
273+
ml_pytest_args.extend(ml_framework_tests)
274+
ml_pytest_args.extend(session.posargs)
275+
276+
ml_env = os.environ.copy()
277+
ml_env["PYTEST_ADDOPTS"] = "-n=4 --dist=loadscope"
278+
279+
# Run py.test against the ML unit tests.
280+
session.run(*ml_pytest_args, env=ml_env)
281+
282+
# Run tests that require isolation.
283+
session.run(
284+
"py.test",
285+
"--quiet",
286+
f"--junitxml=unit_{session.python}_test_vertexai_import_sponge_log.xml",
287+
os.path.join("tests", "unit", "architecture", "test_vertexai_import.py"),
288+
*session.posargs,
289+
)
234290

235291

236292
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@
273273
"pytest-cov",
274274
"mock",
275275
"pytest-xdist",
276+
"pytest-shard",
276277
"Pillow",
277278
"scikit-learn<1.6.0; python_version<='3.10'",
278279
"scikit-learn; python_version>'3.10'",

0 commit comments

Comments
 (0)