tox.ini环境变量替换问题

时间:2019-04-16 19:40:15

标签: python shell tox

我正在使用tox内的目录环境变量将arg传递给shell脚本,该脚本等待数据库迁移完成再开始测试。如果运行此命令,尽管在$1脚本中回显.sh时参数丢失了。

[tox]
envlist = py27
skipsdist=True

[testenv]
passenv = *
deps = -r {env:APP_ROOT}/requirements.txt
commands_pre = {env:APP_ROOT}/scripts/wait-for-db.sh {env:DBSENTINEL}/.db-migrations-ready
usedevelop = true
commands = py.test
commands_post = /bin/rm {env:DBSENTINEL}/.db-migrations-ready

我最终得到

Darwin run-test-pre: commands[0] | /Users/alexander/projects/python-services/scripts/wait-for-db.sh /Users/alexander/projects/python-services/.db-migrations-ready
.db-migrations-ready

除了在shell脚本中回显之外,我要做的是在run-test-pre输出/Users/alexander/projects/python-services/.db-migrations-ready中看到的完整路径。相反,只有.db-migrations-ready通过。

如果我将pre_commands更改为

commands_pre = {env:APP_ROOT}/scripts/wait-for-db.sh {env:DBSENTINEL}//.db-migrations-ready

然后我看到了完全替代的回声

Darwin run-test-pre: commands[0] | /Users/alexander/projects/python-services/scripts/wait-for-db.sh /Users/alexander/projects/python-services//.db-migrations-ready
/Users/alexander/projects/python-services//.db-migrations-ready

我猜想这与转义,格式化或argparse问题有关,但不确定。我需要做的是{env:DBSENTINEL}解压缩设置的目录路径,并以$arg1的形式传递到Shell脚本。

1 个答案:

答案 0 :(得分:0)

单引号似乎可以解决,我认为这与this Github问题有关。

commands_pre = {env:APP_ROOT}/scripts/wait-for-db.sh '{env:DBSENTINEL}/.db-migrations-ready'
Darwin run-test-pre: commands[1] | /Users/alexander/projects/python-services/scripts/wait-for-db.sh /Users/alexander/projects/python-services/.db-migrations-ready
/Users/alexander/projects/cloud/python-services/.db-migrations-ready