Tob*_*bey -1 bash shell quotation-marks pytest
我尝试编写一个脚本,帮助根据用户输入选择pytest选项.不幸的是,脚本总是失败,因为最新的参数与标记有关.
我怀疑标记选项中的引号是问题的根源.不幸的是,我找不到任何解决方法.
这是MWE:
test.sh的内容
#!/bin/bash
options=("-v")
options+=("-m \"not dummy\"")
echo "about to launch pytest ${options[@]}"
pytest ${options[@]}
Run Code Online (Sandbox Code Playgroud)
test_dummy.py的内容:
import pytest
@pytest.mark.dummy
def test_dummy():
assert(True)
Run Code Online (Sandbox Code Playgroud)
现在运行test.sh脚本的输出:
即将推出pytest -v -m"not dummy"====================================== ================================================== =======================================测试会话开始======== ================================================== ================================================== =================== platform linux - Python 3.6.4,pytest-3.3.2,py-1.5.2,pluggy-0.6.0 - /home/[...]/anaconda3/bin/python cachedir:.cache rootdir:/home/[...]/pytest,inifile:pluinsins:cov-2.5.1
================================================== ================================================== ======================没有测试在0.00秒内运行====================== ================================================== ================================================== =错误:找不到文件:dummy"
当然,运行生成的命令
pytest -v -m"not dummy"
完美的工作.如何克服这个问题
先感谢您
不确定,但我认为你的问题来自于将两个参数定义为单个参数.尝试将所有参数分开:
#!/bin/bash
options=("-v")
options+=("-m" "not dummy")
echo "about to launch pytest ${options[@]}"
pytest "${options[@]}"
Run Code Online (Sandbox Code Playgroud)