Repository navigation
Commit f6fe09b
test(train): patch mocks at the lookup site so unit tests stop calling AWS (#6491)
Five tests in sagemaker-train's unit suite issued real AWS requests. They
pass in CI only because the build role carries credentials, so the mocks
were silently ineffective rather than visibly broken.
Root cause in three shapes:
1. Patch targeting the defining module instead of the lookup site.
base_trainer does `from ...finetune_utils import get_recipe_s3_uri` at
module level, so patching finetune_utils.get_recipe_s3_uri never rebinds
the reference base_trainer already holds and the real function ran,
calling DescribeHubContent. Same for get_training_image, and for
TrainDefaults, which handed back a real Session so download_file issued a
live HeadObject.
Only two of the four finetune_utils patches in that block were affected:
_render_recipe_placeholders and _get_smtj_override_spec are imported
inside _train_serverful_smtj, so that import re-executes under patch and
finetune_utils is the correct target for them. Those are left as they are.
2. Missing mock. base_evaluator imports verify_evaluation_caller_permissions
in the same statement as resolve_and_validate_role, but only the latter
was ever patched, so _get_aws_execution_context reached STS
GetCallerIdentity and IAM.
3. Incomplete mock. test_model_trainer_no_from_recipe_raises patched
TrainDefaults.get_role for exactly this reason, but STS was also reached
by a second route: model_post_init builds a default OutputDataConfig,
which calls session.default_bucket(). The session is stubbed rather than
get_output_data_config so that the defaulting logic stays under test.
Verified with deliberately invalid credentials plus a transport-level
recorder that counts swallowed calls:
- the three files go from 5 failed / 97 passed to 102 passed
- the full sagemaker-train unit suite goes from 19 to 14 failures; the
remaining 14 are a local botocore shape mismatch, not these tests
- zero outbound AWS requests from the three files
Coverage moves by one line, 27402 to 27401, with no real loss. The 12 lines
no longer covered are all sagemaker-core session_helper AWS plumbing
(default_bucket, generate_default_sagemaker_bucket_name, botocore_resolver,
sts_regional_endpoint) that these tests only covered by genuinely calling
STS; all 12 are covered by sagemaker-core's own unit suite. Offsetting that,
11 lines become newly covered in base_trainer, base_evaluator,
benchmark_evaluator, custom_scorer_evaluator and model_trainer, because the
tests no longer abort partway through on an AWS error.
No production code changes.
Co-authored-by: Mohamed Zeidan <zeidmo@amazon.com>1 parent b04efc3 commit f6fe09b
3 files changed
Lines changed: 50 additions & 7 deletions
File tree
- sagemaker-train/tests/unit/train
- evaluate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
295 | 300 | | |
296 | 301 | | |
297 | 302 | | |
| |||
307 | 312 | | |
308 | 313 | | |
309 | 314 | | |
310 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
311 | 323 | | |
312 | 324 | | |
313 | 325 | | |
| |||
349 | 361 | | |
350 | 362 | | |
351 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
352 | 367 | | |
353 | 368 | | |
354 | 369 | | |
| |||
373 | 388 | | |
374 | 389 | | |
375 | 390 | | |
| 391 | + | |
376 | 392 | | |
377 | 393 | | |
378 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1565 | 1565 | | |
1566 | 1566 | | |
1567 | 1567 | | |
1568 | | - | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
1569 | 1578 | | |
1570 | | - | |
| 1579 | + | |
1571 | 1580 | | |
1572 | 1581 | | |
1573 | 1582 | | |
1574 | | - | |
| 1583 | + | |
1575 | 1584 | | |
1576 | 1585 | | |
1577 | 1586 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| 555 | + | |
555 | 556 | | |
556 | 557 | | |
557 | 558 | | |
558 | 559 | | |
559 | 560 | | |
560 | | - | |
561 | | - | |
562 | | - | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
563 | 581 | | |
564 | 582 | | |
565 | 583 | | |
| |||
0 commit comments