Tox为缺少的环境变量设置默认值

时间:2017-03-23 16:50:04

标签: python environment-variables tox

我想将默认值设置为tox中缺少的环境变量,但前提是它们缺失。

1 个答案:

答案 0 :(得分:2)

这可以通过env substitution运行。使用TOX_WORKDIR或默认值的示例:

tox.ini

[tox]
envlist = py
skipsdist = true

[testenv]
setenv = TOX_WORKDIR = {env:TOX_WORKDIR:.tox}
commands = python ./envecho.py

envecho.py

#!/usr/bin/env python
import os

print(os.getenv("TOX_WORKDIR"))
输出没有env set:

$ tox

py create: /home/oliver/Dropbox/projects/tox/lab/mini/.tox/py
py installed: appdirs==1.4.3,packaging==16.8,pyparsing==2.2.0,six==1.10.0
py runtests: PYTHONHASHSEED='2704413679'
py runtests: commands[0] | python ./envecho.py
.tox
______________________________ summary ______________________________
  py: commands succeeded
  congratulations :)
使用env set输出:

$ TOX_WORKDIR=/tmp/ tox

py installed: appdirs==1.4.3,packaging==16.8,pyparsing==2.2.0,six==1.10.0
py runtests: PYTHONHASHSEED='30398946'
py runtests: commands[0] | python ./envecho.py
/tmp/
______________________________ summary ______________________________
  py: commands succeeded
  congratulations :)