fix: stop test_sourcecode_args from depending on an ambient HOME - #6383
Open
mohamedzeidan2021 wants to merge 1 commit into
Open
mohamedzeidan2021 wants to merge 1 commit into
mohamedzeidan2021 wants to merge 1 commit into
Conversation
test_environment_variables_in_command_still_expand compared the shell-expanded
command against os.environ["HOME"], which fails with KeyError: 'HOME' on every
Python version in CI. The unit tests run under tox, whose filtered environment
does not pass HOME through, so the variable the test reads is simply absent.
Export a variable the module owns instead, via an autouse fixture, and assert
against its known value. The parametrized literal-argument cases that used
$HOME/${HOME} now use the same variable, so they compare a literal against a
non-empty expansion rather than against whatever the ambient environment
happens to hold.
Test-only change: the SourceCode.args behavior added for aws#5226 is untouched, and
reintroducing the original double-quoted CMD= assignment still fails 23 of the
28 tests in this file, including both reworked cases.
|
Claude finished @mohamedzeidan2021's task in 45s —— View job PR Review: fix test's dependency on ambient
|
This branch was successfully deployed
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 #, if available
Follow-up to #6356 (
feat: add args field to SourceCode for command-based training, which closed #5226). That PR merged with a failing unit test, sounit-tests (sagemaker-train)is red onmaster.Description
tests/unit/train/test_sourcecode_args.py::test_environment_variables_in_command_still_expandfails withKeyError: 'HOME'on py310, py311 and py312:The test built a command containing
$HOME, ran the generated shell fragment, and compared the resulting argv againstos.environ["HOME"]. The unit tests run under tox, whose filtered environment does not passHOMEthrough, so that key is absent in CI. Theenviron({...})dump in the failing traceback confirms it — onlyAWS_*,PATH,TOX_*,PYTHONHASHSEED,VIRTUAL_ENV,LC_CTYPE,PYTEST_*andSAGEMAKER_REGIONare present. It passed locally because interactive shells do setHOME, which is how it got through review.This change makes the file own the variable it asserts on:
SM_TEST_SOURCECODE_ARGS_VALUEwith a known, non-empty value, and the expansion test asserts against that value instead ofos.environ["HOME"].$HOME/${HOME}now use the same variable. Previously, withHOMEunset, those cases compared a literal against an empty expansion; now they compare against a non-empty one, so they fail more loudly if expansion ever leaks back in.This is a test-only change. No production code is touched, so the
SourceCode.argsbehavior added for #5226 is unchanged —git diffis one file undertests/.Testing done
Reproduced the CI failure locally by removing
HOMEfrom the environment, which matches the CI result exactly:After the change, both with and without
HOME:Full
sagemaker-trainunit suite under the CI condition: 2627 passed, 19 skipped.Verified the tests still catch the bug they were written for. Temporarily restoring the pre-#6356
CMD="{base_command}"assignment intemplates.py(the quoting bug that defeatedshlex.quote) fails 23 of 28 tests in the file — including both reworked parametrized cases and the rewritten expansion test — so the regression coverage is intact, not weakened:black --checkandflake8are clean on the changed file.Merge Checklist
Put an
xin the boxes that apply.General
black --checkandflake8locallyTests
HOME)By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.