bash Pipenv Pipfile 脚本中的条件

bash condition within Pipenv Pipfile script

我有一个带有这样脚本的 Pipfile

[script]
tests = "pytest --cov-fail-under=40 tests/"

我想让 cov-fail-under 参数值取决于环境变量。在 Pipfile 脚本之外,以下命令完成工作:

pytest --cov-fail-under=$( case $VARin true ) echo 40 ;; * ) echo 80 ;; esac ) tests/

但是当使用 pipenv run tests 执行时,bash 条件显示为产生以下错误的字符串:

ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: argument --cov-fail-under: invalid validate_fail_under value: '$('

是否有解决此问题的方法?

你可以用 sh -c:

生成 shell

Pipfile

[scripts]
tests = "sh -c '[ \"${VAR}\" = \"true\" ] && mincov=40 ; pytest --cov-fail-under=\"${mincov:-80}\" tests'"