python - 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 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
:
点文件
[scripts]
tests = "sh -c '[ \"${VAR}\" = \"true\" ] && mincov=40 ; pytest --cov-fail-under=\"${mincov:-80}\" tests'"
推荐阅读
- c# - 如何使用 ExcelDataReader 从 c# 中的 excel 文件中逐行(逐行)获取数据
- extjs - 在 extJs 图表中禁用特定系列的图例
- visual-studio-code - 循环选择多个选项并在 vscode 中单独编辑
- sql - Postgresql,为另一个表中的每一行更新表行
- vuex - 我怎样才能解决这个问题?Splice 不是 Vuex 的函数
- asp.net-core - 无法将图片上传到控制器(FormFile、ASP .NET)
- android - 如何迭代对象列表但在特定字段Kotlin
- macos - 安装 OpenCV 时 CMake 抛出错误
- excel - 在 Excel 中,我需要以天小时分钟秒为单位转换秒数
- html - HTML flexbox 自定义间距,带空格 - 在创建添加项之间