A H
A H

Reputation: 2580

tox multiple tests, re-using tox environment

Is it possible to do the following using a single tox virtual environment?

[tox]
envlist = test, pylint, flake8, mypy
skipsdist = true

[testenv:lint]
deps = pylint
commands = pylint .

[testenv:flake8]
deps = flake8
commands = flake8 .

[testenv:mypy]
commands = mypy . --strict

[testenv:test]
deps = pytest
commands = pytest


As I am only testing on my python version (py3.7), I don't want tox to have to create 4 environments (.tox/test, .tox/pylint,.tox/flake8, .tox/mypy) when they could all be run on a single environment.

I also want to see what failed individually individually, thus don't want to do:

[tox]
skipsdist = true

[testenv]
commands = pylint .
           flake8 .
           mypy . --strict
           pytest

as the output would be like this:

_____________ summary ___________
ERROR:   python: commands failed

and not like this:

____________________summary _________________
ERROR:   test: commands failed
ERROR:   lint: commands failed
ERROR:   mypy: commands failed
  test: commands succeeded

Upvotes: 9

Views: 5157

Answers (1)

mikenerone
mikenerone

Reputation: 2045

Use generative names and factor-specific commands (search the tox configuration doc page for those terms for more info) to implement all of your desired environments as one so they share the same envdir:

[testenv:{lint,flake8,mypy,test}]
envdir = {toxworkdir}/.work_env
deps = pylint, flake8, pytest
commands =
    lint: pylint .
    flake8: flake8 .
    mypy: mypy . --strict
    test: pytest

In tox 4+, you may use the plugin tox-ignore-env-name-mismatch and set runner = ignore_env_name_mismatch in the testenv to allow testenvs with different names to share the same virtualenv.

Upvotes: 10

Related Questions