Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_hook_writes_to_stderr failure "/bin/sh command not found" #1383

Closed
zaro0508 opened this issue Nov 13, 2023 · 4 comments
Closed

test_hook_writes_to_stderr failure "/bin/sh command not found" #1383

zaro0508 opened this issue Nov 13, 2023 · 4 comments

Comments

@zaro0508
Copy link
Contributor

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

  1. poetry install
  2. pyenv shell 3.9
  3. ➜ python -V
    Python 3.9.7
  4. ➜ /bin/sh --version
    GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin23)
    Copyright (C) 2007 Free Software Foundation, Inc.
  5. 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
@zaro0508
Copy link
Contributor Author

This test was added in PR #1372, do you know anything about it @iainelder ?

@iainelder
Copy link
Contributor

Yes, I added it. Not sure why it would fail. I'll take a look tomorrow!

@iainelder
Copy link
Contributor

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.

@iainelder
Copy link
Contributor

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.

iainelder added a commit to iainelder/sceptre that referenced this issue Nov 22, 2023
The old test expected `/bin/sh` to write Dash's error message. This works on
Ubuntu 20.

It old test failed  when `/bin/sh` pointed to `/bin/bash`. This happens on
macOS.

The new test no longer depends on system-defined side effects of a missing
command. It just writes to the standard error stream and checks that the same
text comes out.
iainelder added a commit to iainelder/sceptre that referenced this issue Nov 22, 2023
The old test expected `/bin/sh` to write Dash's error message. This works on
Ubuntu 20.

It old test failed  when `/bin/sh` pointed to `/bin/bash`. This happens on
macOS.

The new test no longer depends on system-defined side effects of a missing
command. It just writes to the standard error stream and checks that the same
text comes out.
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

No branches or pull requests

2 participants