Skip to content

When I use Shell script to run PyTest, some ERROR jumped up. #10539

Answered by The-Compiler
lucky33newman asked this question in Q&A
Discussion options

You must be logged in to vote

Please format code as code in the future, as your post is almost unreadable. I edited it to add code blocks.

This isn't a pytest issue, it's a shell issue. If you use variables in a shell script, they need to be quoted when using them, to avoid splitting arguments at spaces. In a case like this, it's cleanest use an array instead:

suffix=("-m" "not dangerous")
...
pytest "${suffix[@]}"

See Quotes - Greg's Wiki and Words... [Bash Hackers Wiki] for more explanation around it.

I'd also recommend using ShellCheck, as it points out things like this:

[Line 3:]
suffix="-m 'not dangerous'"
        ^-- [SC2089](https://www.shellcheck.net/wiki/SC2089) (warning): Quotes/backslashes will be treated l…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@lucky33newman
Comment options

Answer selected by The-Compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants