Skip to content

[Resolve #1520] Fix test for cmd hook shell option#1552

Open
iainelder wants to merge 1 commit intoSceptre:masterfrom
iainelder:fix-test-for-cmd-hook-shell-option
Open

[Resolve #1520] Fix test for cmd hook shell option#1552
iainelder wants to merge 1 commit intoSceptre:masterfrom
iainelder:fix-test-for-cmd-hook-shell-option

Conversation

@iainelder
Copy link
Contributor

The previous version of this test meant to use bash, but really used sh.

Improves first PR #1523.

PR Checklist

  • Wrote a good commit message & description [see guide below].
  • Commit message starts with [Resolve #issue-number].
  • Added/Updated unit tests.
  • Added/Updated integration tests (if applicable).
  • All unit tests (poetry run tox) are passing.
  • Used the same coding conventions as the rest of the project.
  • The new code passes pre-commit validations (poetry run pre-commit run --all-files).
  • The PR relates to only one subject with a clear title.
    and description in grammatically correct, complete sentences.

Approver/Reviewer Checklist

  • Before merge squash related commits.

Other Information

Guide to writing a good commit

The previous version of this test meant to use bash, but really
used sh.

Improves first PR Sceptre#1523.
@iainelder iainelder requested a review from dboitnot April 4, 2025 15:17
@iainelder
Copy link
Contributor Author

@dboitnot , does this still work on Nix?

@zaro0508 zaro0508 requested a review from alex-harvey-z3q April 4, 2025 15:51
def test_shell_parameter_sets_the_shell(stack, capfd):
# Determine the local path to bash (it's not always /bin/bash)
Cmd("echo $0", stack).run()
Cmd("which bash", stack).run()
Copy link
Contributor

@zaro0508 zaro0508 Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is too specific and would make this unit test fail on developer systems without bash. Can you think of a more generic way to validate the correctly loaded shell?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using Python as the test shell?

Use sys.executable to get the absolute path to the interpreter.

Then pass "print(sys.executable)" as the command and check that it's still Python in the stdout.

Python supports the -c option, which makes it a shell in this context.

Copy link
Contributor

@zaro0508 zaro0508 Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea but how about just using python's subprocess.run directly?

➜ python
Python 3.12.11 (main, Nov  3 2025, 12:02:03) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run(["which","bash"], capture_output=True, text=True)
CompletedProcess(args=['which', 'bash'], returncode=0, stdout='/bin/bash\n', stderr='')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the box idea here, since this is really just testing that the parameter is being respected, try testing with a shell parameter for something that will never exist, and capture the exception to assert. something like

with pytest.raises(OSError):
    Cmd({"run": "echo $0", "shell":  "nonexistantshellprovidedbyuser"}, stack).run()

As an aside, if the test environment were to be dockerized, then one could guarantee that bash exists in the env and this would no be an issue

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.

4 participants