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_shell_error() doesn't catch the right regex on macOS in zsh #45

Closed
drewbrew opened this issue Nov 15, 2023 · 1 comment · Fixed by #46
Closed

test_shell_error() doesn't catch the right regex on macOS in zsh #45

drewbrew opened this issue Nov 15, 2023 · 1 comment · Fixed by #46

Comments

@drewbrew
Copy link
Contributor

Hey, I'm not sure whether macOS or zsh is at fault here, but if you run tox on macOS, the test_shell_error() test fails to match the regex:

tox -e py311-dj41-sqlite
# snip
.tox/py311-dj41-sqlite/lib/python3.11/site-packages/django_migrations_ci/shell.py:23: MigrateCIShellException

During handling of the above exception, another exception occurred:

    def test_shell_error():
>       with pytest.raises(shell.MigrateCIShellException, match="/bin/sh: 1: oof: not found\n"):
E       AssertionError: Regex pattern did not match.
E        Regex: '/bin/sh: 1: oof: not found\n'
E        Input: '/bin/sh: oof: command not found\n'

tests/test_shell.py:12: AssertionError

Here's what I believe will fix it:

diff --git a/tests/test_shell.py b/tests/test_shell.py
index 56a14c7..d3a0765 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -9,7 +9,10 @@ def test_shell_ok():


 def test_shell_error():
-    with pytest.raises(shell.MigrateCIShellException, match="/bin/sh: 1: oof: not found\n"):
+    with pytest.raises(
+        shell.MigrateCIShellException,
+        match=r"/bin/sh: (1: )?oof: (command )?not found\n",
+    ):
         shell.exec("oof")

If you think this is worth adding in, I'm happy to throw up a quick PR.

@iurisilvio
Copy link
Collaborator

The exact message is not important, just have to check the command failed properly. Checking for something like oof.+not found is good enough.

I don't have a mac to try it, but I'd like to support it too. Please, PR! 🙏🏻

drewbrew added a commit to drewbrew/django-migrations-ci that referenced this issue Nov 19, 2023
Fixes businho#45 because the default shell on macOS returns
`/bin/sh: oof: command not found\n` which doesn't quite match the
regex provided.

After discussion with @iurisilvio, using a fairly lax regex which
just looks for "oof" followed by "not found" is good enough.
iurisilvio pushed a commit that referenced this issue Nov 19, 2023
Fixes #45 because the default shell on macOS returns
`/bin/sh: oof: command not found\n` which doesn't quite match the
regex provided.

After discussion with @iurisilvio, using a fairly lax regex which
just looks for "oof" followed by "not found" is good enough.
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 a pull request may close this issue.

2 participants