4

e.g. Let's say I have following in tox.ini

[tox]
envlist = py27, py35, testenv2

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv:testenv2]  
 # settings related to testenv2 - includes deps, commands

Now when I run tox command, it invokes testenv commands with python 2.7 and 3.5 interpreter but testenv2 commands only with base python installed on the machine (in my case 2.7). How to get tox to also test a "named" (non-default) test environment like testenv2 to be tested with multiple python versions?

Viral Modi
  • 1,957
  • 1
  • 9
  • 18

4 Answers4

2

The first answer describes two viable ways. For completeness: you can also generate environments and use conditional settings - e.g.:

[tox]
skipsdist = True
envlist = py{27,35}-{test,lint}
[testenv]
skip_install = True
deps =
    test: pytest
    test: pytest-xprocess
    lint: flake8
    lint: black
commands =
    test: pytest -v
    lint: flake8
    lint: black .

would generate (tox -a):

py27-test
py27-lint
py35-test
py35-lint

You can use any factor (e.g. py27 or test) to conditionally add commands, deps, etc.

See also the docs.

BTW: to see which settings each testenv exactly has you can run tox --showconfig.

Oliver Bestwalter
  • 5,219
  • 33
  • 47
0

List all environments explicitly:

[tox]
envlist = py27, py35, py27-testenv2, py35-testenv2

If that's not enough refactor tox.ini:

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv2]  
 # settings related to testenv2 - includes deps, commands

[testenv:py27-testenv2]  
deps = {[testenv2]deps}
commands = {[testenv2]commands}

[testenv:py35-testenv2]  
deps = {[testenv2]deps}
commands = {[testenv2]commands}
phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    The first way doesn't work. I didn't try the second way but found another way similar to yours. Will post an answer soon – Viral Modi Aug 09 '18 at 05:35
0

I could get the "named" test environment to be tested with multiple python versions by making multiple "named" test environments, one each for the different python versions I wanted it to be tested with and using the basepython option to specify the python version for the test environment to be tested with. Below is the example that works:

[tox]
envlist = py27, py35, testenv2_py27, testenv2_py35

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv:testenv2_py27]
basepython = python2.7 
 # settings related to testenv2 - includes deps, commands

[testenv:testenv2_py35]
basepython = python3.5  
 # settings related to testenv2 - includes deps, commands
Viral Modi
  • 1,957
  • 1
  • 9
  • 18
0

Just in case someone still needs this, I figured out an even more concise solution. It combines all the good suggestions from the other answers:

[tox]
envlist = py{27,35}, testenv2-py{27,35}

[testenv]  
 # settings related to "default" testenv - includes deps, commands

[testenv:testenv2-py{27,35}]
 # settings related to testenv2 - includes deps, commands