如何在tox中导入所有环境变量 [英] How to import all the environment variables in tox

查看:43
本文介绍了如何在tox中导入所有环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 setenv 中使用以下命令从我运行的地方导入环境变量,但是有没有办法导入所有变量,这样我就不需要逐个导入了.

I'm using following in setenv to import the environment variable from where I run, but is there a way to import all the variables so that I don't really need to import one by one.

例如:{env:TEMPEST_CONFIG:} 和 {env:TEMPEST_CONFIG_DIR:} 用于导入这两个变量.

e.g: {env:TEMPEST_CONFIG:} and {env:TEMPEST_CONFIG_DIR:} used to import these 2 variables.

[testenv:nosetests]
setenv =
    TEMPEST_CONFIG={env:TEMPEST_CONFIG:}
    TEMPEST_CONFIG_DIR={env:TEMPEST_CONFIG_DIR:}
deps = {[testenv]deps}
commands =
    find . -type f -name "*.pyc" -delete
    bash {toxinidir}/tools/setup.sh
    nosetests --with-xunit {posargs}

推荐答案

您可以使用 passenv.如果您传递 catch all 通配符 *,您就可以访问父环境中的所有环境变量:

You can use passenv. If you pass the catch all wildcard * you have access to all environment variables from the parent environment:

passenv=SPACE-SEPARATED-GLOBNAMES

passenv=SPACE-SEPARATED-GLOBNAMES

2.0 版中的新功能.

应复制的通配符环境变量名称列表从 tox 调用环境到测试环境时执行测试命令.如果指定的环境变量没有存在于 tox 调用环境中,它被忽略.您可以使用 *和 ?以一个名称匹配多个环境变量.

A list of wildcard environment variable names which shall be copied from the tox invocation environment to the test environment when executing test commands. If a specified environment variable doesn’t exist in the tox invocation environment it is ignored. You can use * and ? to match multiple environment variables with one name.

最小的 tox.ini 重现(不需要项目):

minimal tox.ini to reproduce (no project necessary):

[tox]
skipsdist = True

[testenv]
passenv = *
skip_install = True
commands = python -c "print('computer says {env:MY_FANCY_ENV_VAR:}!')"

在 linux/unix shell 中调用:

invocation in linux/unix shell:

MY_FANCY_ENV_VAR=no tox -qq

在 Windows cmd.exe 上调用:

invocation on Windows cmd.exe:

set MY_FANCY_ENV_VAR=no & tox -qq

输出:

computer says no!

这篇关于如何在tox中导入所有环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆