0
votes

I want to run my test with different values of environment variables. I have this tox.ini, which doesn't do what I want:

# tox.ini

[tox]
envlist = py37-{foo,bar}

[testenv]
description = Tests common
setenv =
    MY_VAR=COMMON
commands =
    env

[testenv:foo]
description = Tests foo
setenv =
    MY_VAR=FOO

[testenv:bar]
description = Tests bar
setenv =
    MY_VAR=BAR 

Above ini produced the following output:

$ tox
GLOB sdist-make: 

***

py37-foo run-test: commands[0] | env

***

MY_VAR=COMMON                                 <<<--- MY_VAR=foo is expected

***

py37-bar run-test: commands[0] | env

***

MY_VAR=COMMON                                 <<<--- MY_VAR=bar is expected

Whats wrong?

I use:

  • Win 10.0.18363 Build 18363
  • Python 3.7.4
  • tox: 3.14.0
2

2 Answers

1
votes

tox doesn't combine environments. Every environment is derived from [testenv] but other environments are not considered for inclusion. You have to combine them yourself in tox.ini. This should work:

[tox]
envlist = py37-{foo,bar}

[testenv]
description = Tests common
setenv =
    MY_VAR=COMMON
commands =
    env

[foo]
description = Tests foo
setenv =
    MY_VAR=FOO

[bar]
description = Tests bar
setenv =
    MY_VAR=BAR

[testenv:py37-foo]
description = Tests py37 foo
setenv = {[foo]setenv}

[testenv:py37-bar]
description = Tests py37 bar
setenv = {[bar]setenv}
1
votes

The key is the Compressing dependency matrix. This technique results compact, and non-redundant solution:

[tox]
envlist = py37-{foo,bar,baz}

[testenv]
setenv =
    MY_VAR=COMMON
    foo: MY_VAR=FOO
    bar: MY_VAR=BAR
commands =
    env