test_hook_writes_to_stderr failure "/bin/sh command not found"
zaro0508 opened this issue · 4 comments
Subject of the issue
FAILED tests/test_hooks/test_cmd.py::test_hook_writes_to_stderr - AssertionError: assert '/bin/sh: mis...and not found' == '/bin/sh: 1: ...nd: not found'
when I run Sceptre unit test.
Your environment
- Sceptre v 4.3.0
- Python v 3.9
- MAC OSX Sonoma 14.0
Steps to reproduce
- poetry install
- pyenv shell 3.9
- ➜ python -V
Python 3.9.7 - ➜ /bin/sh --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin23)
Copyright (C) 2007 Free Software Foundation, Inc. - poetry run pytest
Expected behaviour
All tests pass
Actual behaviour
1 test failure..
stack = sceptre.stack.Stack(name='stack1', project_code=project1, template_handler_config={'template': 'path.yaml'}, region=re...ions=[], on_failure=None, disable_rollback=False, stack_timeout=0, stack_group_config={}, ignore=False, obsolete=False)
capfd = <_pytest.capture.CaptureFixture object at 0x1102a76d0>
def test_hook_writes_to_stderr(stack, capfd):
with pytest.raises(Exception):
Cmd("missing_command", stack).run()
cap = capfd.readouterr()
assert cap.out.strip() == ""
> assert cap.err.strip() == "/bin/sh: 1: missing_command: not found"
E AssertionError: assert '/bin/sh: mis...and not found' == '/bin/sh: 1: ...nd: not found'
E - /bin/sh: 1: missing_command: not found
E ? ---
E + /bin/sh: missing_command: command not found
E ? ++++++++
tests/test_hooks/test_cmd.py:150: AssertionError
This test was added in PR #1372, do you know anything about it @iainelder ?
Yes, I added it. Not sure why it would fail. I'll take a look tomorrow!
To follow your repro I need to install pyenv. I'll figure out how to do that this week.
What do you see when you skip the pyenv command and run poetry run tox -e py39
?
For me, all the tests pass in tox's py39 environment.
Your /bin/sh
points to Bash. (It looks like your system is macOS.)
My /bin/sh
points to Dash. My system is Ubuntu 20.
The shells write different error messages when they can't find the command.
- Bash:
/bin/bash: missing_command: command not found
- Dash:
/bin/dash: 1: missing_command: not found
The test expects /bin/sh
to write Dash's error message.
Your /bin/sh
writes Bash's error message, and so the test fails.
All I want to test here is that the hook writes to the standard error stream.
I think I should rewrite it so that it no longer depends on system-defined side effects of a missing command.
A simpler test would just echo text to the standard error stream and check that the same text comes out.