|
69 | 69 | "pytest-asyncio", |
70 | 70 | # Preventing: py.test: error: unrecognized arguments: -n=auto --dist=loadscope |
71 | 71 | "pytest-xdist", |
| 72 | + "pytest-shard", |
72 | 73 | ] |
73 | 74 | UNIT_TEST_EXTERNAL_DEPENDENCIES = [] |
74 | 75 | UNIT_TEST_LOCAL_DEPENDENCIES = [] |
@@ -196,41 +197,96 @@ def install_unittest_dependencies(session, *constraints): |
196 | 197 |
|
197 | 198 |
|
198 | 199 | 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. |
200 | 201 |
|
201 | | - constraints_path = str( |
| 202 | + constraints_path = str( |
202 | 203 | CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" |
203 | 204 | ) |
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 | + ) |
234 | 290 |
|
235 | 291 |
|
236 | 292 | @nox.session(python=UNIT_TEST_PYTHON_VERSIONS) |
|
0 commit comments