Skip to content

Commit aa6553a

Browse files
committed
test: assert finder pass-through via find_spec, not real import
test_finder_does_not_shadow_real_v3_packages imported sagemaker.train / sagemaker.serve to prove the fallback finder does not shadow them. That assumed those packages are installed -- but the sagemaker-core unit-test CI job installs sagemaker-core only, so the import raised ModuleNotFoundError and the test failed. Assert the actual contract instead: the finder's find_spec() returns None (pass-through) for real v3 top-level packages, which needs no import and holds in a core-only environment. Also covers mlops and lineage.
1 parent 15eb00b commit aa6553a

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

‎sagemaker-core/tests/unit/test_removed_v2_modules.py‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,26 @@ def test_uncovered_module_falls_back_to_guidance(module):
141141
assert any(issubclass(x.category, DeprecationWarning) for x in w)
142142

143143

144-
@pytest.mark.parametrize("module", ["sagemaker.core", "sagemaker.train", "sagemaker.serve"])
144+
@pytest.mark.parametrize(
145+
"module",
146+
[
147+
"sagemaker.core",
148+
"sagemaker.train",
149+
"sagemaker.serve",
150+
"sagemaker.mlops",
151+
"sagemaker.lineage",
152+
],
153+
)
145154
def test_finder_does_not_shadow_real_v3_packages(module):
146155
import sagemaker.core # noqa: F401 -- ensure finder registered
147156

148-
# Real v3 packages must import cleanly, untouched by the fallback finder.
149-
_fresh_import(module)
157+
# The fallback finder must not intercept real v3 packages: find_spec must
158+
# return None (pass-through), regardless of whether the package happens to
159+
# be installed in the current environment. (The sagemaker-core unit-test job
160+
# installs core only, so sagemaker.train/serve/mlops are not importable
161+
# there -- asserting find_spec pass-through avoids that false dependency.)
162+
finder = _RemovedV2ModuleFinder()
163+
assert finder.find_spec(module) is None
150164

151165

152166
def test_finder_ignores_non_sagemaker_and_nested():

0 commit comments

Comments
 (0)