python tox: how to use a different python envlist in environment

Viewed 9536

Here is my tox.ini:

[tox]
envlist = py27,py35

[testenv]
deps =
    Flask
    connexion
    pytest
    coverage
    pytest-cov
    requests
    six
commands=pytest --junitxml xunit-reports/xunit-result-XXX.xml --cov {envsitepackagesdir} --cov-report=xml

[testenv:local]
#HOW DO I SPECIFY A NEW LIST OF PYENV LIKE 31,36 IN HERE????
commands=
    pytest --cov {envsitepackagesdir}/XXX  --cov-report html

When I run tox it runs in py27 and py35. I want tox -e local to run in a different set of multiple python environments. I can't figure out how to do this. How do I do this? Right now it does not even respect the intial envlist and only runs on Python 2.7.

5 Answers

A possible solution to what you are attempting to do is to use tox -l to list all the environments, filter the ones you want, and then feed them back into tox -e.

For example, to run all environments that have "local" in the name (using bash):

tox -e $(tox -l | grep local | paste -sd "," -)

Step-by-step explanation:

  • tox -l lists all the environments, one on each line
  • grep local filters only the lines of the input which contain the word "local"
  • paste -sd "," - joins the lines of the input with commas

Use generative envlist and factor-conditional settings.

[tox]
envlist = {py27,py31,py35,py36}-{default,local}

[testenv]
deps =
    Flask
    connexion
    pytest
    coverage
    pytest-cov
    requests
    six

commands =
    {default,local}: python --version
    default: pytest --junitxml xunit-reports/xunit-result-XXX.xml --cov {envsitepackagesdir} --cov-report=xml
    local: pytest --cov {envsitepackagesdir}/XXX  --cov-report html

List all possible combinations of python version and factors using: tox -l

For your "local" case you'd invoke tox in the one of the following ways:

  • tox -e py31-local
  • tox -e py36-local
  • tox -e 'py3{1,6}'-local

Answer heavily influenced by @oliver-bestwalter's answer, but I couldn't get that to work properly for some reason.

Related