test: un-shadow 18 duplicate-named test classes that never ran - #6265
Open
Anai-Guo wants to merge 1 commit into
Open
test: un-shadow 18 duplicate-named test classes that never ran#6265Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
Five test classes are declared twice in the same module. Python binds
the later declaration, so the earlier class object is discarded before
pytest ever sees it and every test method it contains is silently
skipped - the suite still reports green.
Renaming the later declaration restores the shadowed tests:
sagemaker-core/tests/unit/local/test_image.py
TestVolume -> TestVolumeInit (6 recovered)
TestHostingContainer -> TestHostingContainerLifecycle (3 recovered)
sagemaker-core/tests/unit/test_jumpstart_utils.py
TestRemoveEnvVarFromEstimatorKwargsIfAcceptEulaPresent
-> ...Values (1 recovered)
sagemaker-core/tests/unit/helper/test_session_helper.py
TestGenerateDefaultSagemakerBucketName
-> ...Regions (1 recovered)
sagemaker-serve/tests/unit/test_model_builder_servers.py
TestModelBuilderServersConstants
-> ...Types (7 recovered)
The two declarations always hold disjoint method names, so this is real
lost coverage, not duplication. The new names follow each file's own
suffix convention (TestSageMakerContainerExtended, TestPullImageExtended,
TestParseSagemakerVersionEdgeCases, ...); TestHostingContainerExtended
was already taken, hence Lifecycle.
One of the recovered tests needed a fix to pass on Linux.
_HostingContainer.down() branches on os.name, but both recovered
down tests patched platform.system, which the method never consults:
* test_hosting_container_down_unix passed on Linux by accident and
failed anywhere os.name == "nt".
* test_hosting_container_down_windows was worse - on Linux it took
the Unix branch and called the real kill_child_processes() with a
Mock pid.
Both now patch sagemaker.core.local.image.os.name, the value the code
actually reads, and the Windows case additionally asserts that
kill_child_processes is not called.
Verification (pytest --collect-only, before -> after):
tests/unit/local/test_image.py 74 -> 83
tests/unit/test_jumpstart_utils.py 176 -> 177
tests/unit/helper/test_session_helper.py 103 -> 104
sagemaker-serve .../test_model_builder_servers.py 36 -> 43
All 18 recovered tests pass. test_image.py was also run with os.name
forced to "posix" to confirm the platform-gated tests behave on Linux:
same result on both. The only failure in these files,
TestSageMakerContainerExtended::test_create_tmp_folder, fails
identically before and after this change (pre-existing, unrelated).
Only the five class-declaration lines and the two down() tests are
touched; no unrelated reformatting.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Anai-Guo
requested a deployment
to
manual-approval
September 12, 2026 13:49 — with
GitHub Actions
Waiting
Anai-Guo
requested a deployment
to
manual-approval
September 12, 2026 13:49 — with
GitHub Actions
Waiting
Anai-Guo
requested a deployment
to
manual-approval
September 12, 2026 13:49 — with
GitHub Actions
Waiting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Five test classes are declared twice in the same module. Python binds the later declaration, so the earlier class object is discarded before pytest ever collects it — every test method it contains is silently skipped, and the suite still reports green.
In all five cases the two declarations hold disjoint method names, so this is genuine lost coverage rather than duplication.
sagemaker-core/tests/unit/local/test_image.pyTestVolume(L41 vs L1137)test_volume_with_container_dir,test_volume_with_channel,test_volume_raises_without_container_dir_or_channel,test_volume_raises_with_both_container_dir_and_channel,test_volume_selinux_enabled_on_linux,test_volume_darwin_var_pathsagemaker-core/tests/unit/local/test_image.pyTestHostingContainer(L491 vs L1164)test_hosting_container_run,test_hosting_container_down_unix,test_hosting_container_down_windowssagemaker-core/tests/unit/test_jumpstart_utils.pyTestRemoveEnvVarFromEstimatorKwargsIfAcceptEulaPresent(L394 vs L1896)test_remove_env_var_accept_eula_nonesagemaker-core/tests/unit/helper/test_session_helper.pyTestGenerateDefaultSagemakerBucketName(L531 vs L993)test_generate_default_sagemaker_bucket_namesagemaker-serve/tests/unit/test_model_builder_servers.pyTestModelBuilderServersConstants(L189 vs L511)test_*_constantcasesFix
Rename the later declaration in each file. The new names follow each file's own existing suffix convention (
TestSageMakerContainerExtended,TestPullImageExtended,TestParseSagemakerVersionEdgeCases,TestUploadDataSpotCheck, …):TestVolume→TestVolumeInitTestHostingContainer→TestHostingContainerLifecycle(TestHostingContainerExtendedis already taken at L1420)TestRemoveEnvVarFromEstimatorKwargsIfAcceptEulaPresent→…ValuesTestGenerateDefaultSagemakerBucketName→…RegionsTestModelBuilderServersConstants→…TypesOne recovered test needed a real fix
_HostingContainer.down()branches onos.name:but both recovered
downtests patchedplatform.system, which the method never consults:test_hosting_container_down_unixpassed on Linux only by accident, and failed anywhereos.name == "nt".test_hosting_container_down_windowswas worse — on Linux it took the Unix branch and called the realkill_child_processes()with aMockpid. Merging the rename alone would have turned CI red.Both now patch
sagemaker.core.local.image.os.name— the value the code actually reads — and the Windows case additionally assertskill_child_processesis not called.Verification
pytest --collect-only, before → after:sagemaker-core/tests/unit/local/test_image.pysagemaker-core/tests/unit/test_jumpstart_utils.pysagemaker-core/tests/unit/helper/test_session_helper.pysagemaker-serve/tests/unit/test_model_builder_servers.pyAll 18 recovered tests pass.
test_image.pywas additionally run withos.nameforced to"posix"to confirm the platform-gated tests behave the same on Linux — identical results on both.The only failure in these files,
TestSageMakerContainerExtended::test_create_tmp_folder, fails identically with and without this change (pre-existing, unrelated, and Windows-local).Only the five class-declaration lines and the two
down()tests are touched — no unrelated reformatting.+11 / −11.🤖 Generated with Claude Code