Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import all the environment variables in tox

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.

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} 
like image 407
Manjunath Kumatagi Avatar asked Jul 02 '15 18:07

Manjunath Kumatagi


1 Answers

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

New in version 2.0.

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.

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:}!')" 

invocation in linux/unix shell:

MY_FANCY_ENV_VAR=no tox -qq 

invocation on Windows cmd.exe:

set MY_FANCY_ENV_VAR=no & tox -qq 

output:

computer says no! 
like image 145
Oliver Bestwalter Avatar answered Sep 24 '22 13:09

Oliver Bestwalter