Skip to content

test: un-shadow 18 duplicate-named test classes that never ran - #6265

Open
Anai-Guo wants to merge 1 commit into
aws:masterfrom
Anai-Guo:test-unshadow-duplicate-test-classes
Open

test: un-shadow 18 duplicate-named test classes that never ran#6265
Anai-Guo wants to merge 1 commit into
aws:masterfrom
Anai-Guo:test-unshadow-duplicate-test-classes

Conversation

@Anai-Guo

Copy link
Copy Markdown

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.

file class recovered
sagemaker-core/tests/unit/local/test_image.py TestVolume (L41 vs L1137) 6test_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_path
sagemaker-core/tests/unit/local/test_image.py TestHostingContainer (L491 vs L1164) 3test_hosting_container_run, test_hosting_container_down_unix, test_hosting_container_down_windows
sagemaker-core/tests/unit/test_jumpstart_utils.py TestRemoveEnvVarFromEstimatorKwargsIfAcceptEulaPresent (L394 vs L1896) 1test_remove_env_var_accept_eula_none
sagemaker-core/tests/unit/helper/test_session_helper.py TestGenerateDefaultSagemakerBucketName (L531 vs L993) 1test_generate_default_sagemaker_bucket_name
sagemaker-serve/tests/unit/test_model_builder_servers.py TestModelBuilderServersConstants (L189 vs L511) 7 — the seven test_*_constant cases

Fix

Rename the later declaration in each file. The new names follow each file's own existing suffix convention (TestSageMakerContainerExtended, TestPullImageExtended, TestParseSagemakerVersionEdgeCases, TestUploadDataSpotCheck, …):

  • TestVolumeTestVolumeInit
  • TestHostingContainerTestHostingContainerLifecycle (TestHostingContainerExtended is already taken at L1420)
  • TestRemoveEnvVarFromEstimatorKwargsIfAcceptEulaPresent…Values
  • TestGenerateDefaultSagemakerBucketName…Regions
  • TestModelBuilderServersConstants…Types

One recovered test needed a real fix

_HostingContainer.down() branches on os.name:

def down(self):
    if os.name != "nt":
        sagemaker.core.local.utils.kill_child_processes(self.process.pid)
    self.process.terminate()

but both recovered down tests patched platform.system, which the method never consults:

  • test_hosting_container_down_unix passed on Linux only 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. 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 asserts kill_child_processes is not called.

Verification

pytest --collect-only, before → after:

file before after
sagemaker-core/tests/unit/local/test_image.py 74 83
sagemaker-core/tests/unit/test_jumpstart_utils.py 176 177
sagemaker-core/tests/unit/helper/test_session_helper.py 103 104
sagemaker-serve/tests/unit/test_model_builder_servers.py 36 43

All 18 recovered tests pass. test_image.py was additionally run with os.name forced 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant