【问题标题】:bash condition within Pipenv Pipfile scriptPipenv Pipfile 脚本中的 bash 条件
【发布时间】:2021-02-17 15:01:35
【问题描述】:

我有一个带有此类脚本的 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: '$('

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

【问题讨论】:

    标签: python bash scripting pipenv


    【解决方案1】:

    您可以使用sh -c 生成一个shell:

    点文件

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

    【讨论】:

    • 顺便说一下,建议的方法在 pipenv 的脚本中不起作用ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: argument --cov-fail-under: invalid validate_fail_under value: '${MIN_COVERAGE:-40}'
    • 你用了单引号吗?还是只是错误消息?如果是这样,您可以尝试双引号吗?我必须安装 pipenv 来测试它,可以。
    猜你喜欢
    • 1970-01-01
    • 2018-12-31
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 2019-03-26
    • 2018-09-06
    • 2019-03-27
    • 1970-01-01
    相关资源
    最近更新 更多