首页 > 解决方案 > Pipenv Pipfile 脚本中的 bash 条件

问题描述

我有一个带有这样脚本的 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 testsbash 条件执行时,会显示为产生以下错误的字符串:

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

有什么办法可以解决这个问题吗?

标签: pythonbashscriptingpipenv

解决方案


您可以使用以下命令生成外壳sh -c

点文件

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

推荐阅读