When I use Shell script to run PyTest, some ERROR jumped up. #10539
-
Hello, When I use Shell script to run pytest. In the Shell script, the contents are: #!/usr/bin/sh
cd /usr/pytest/
pytest -m "not dangerous" It works well, but when I write the Shell script like this: #!/usr/bin/sh
suffix="-m 'not dangerous'"
cd /usr/pytest/
pytest ${suffix} I just get a ERROR message like this:
I mean to run command like [pytest -m 'not dangerous'] Why it became like this? I just can not understand. Help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
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:
|
Beta Was this translation helpful? Give feedback.
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:
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: