===
Tox
===

When using `tox <https://tox.wiki/en/stable/>`_ you can have ultra-compact configuration - you can have all of it in
``tox.ini``::

    [tox]
    envlist = ...

    [tool:pytest]
    ...

    [coverage:paths]
    ...

    [coverage:run]
    ...

    [coverage:report]
    ..

    [testenv]
    commands = ...

An usual problem users have is that pytest-cov will erase the previous coverage data by default, thus if you run tox
with multiple environments you'll get incomplete coverage at the end.

To prevent this problem you need to use ``--cov-append``. It's still recommended to clean the previous coverage data to
have consistent output. A ``tox.ini`` like this should be enough for sequential runs::

    [tox]
    envlist = clean,py27,py36,...

    [testenv]
    commands = pytest --cov --cov-append --cov-report=term-missing ...
    deps =
        pytest
        pytest-cov

    [testenv:clean]
    deps = coverage
    skip_install = true
    commands = coverage erase

For parallel runs we need to set some dependencies and have an extra report env like so::

    [tox]
    envlist = clean,py27,py36,report

    [testenv]
    commands = pytest --cov --cov-append --cov-report=term-missing
    deps =
        pytest
        pytest-cov
    depends =
        {py27,py36}: clean
        report: py27,py36

    [testenv:report]
    deps = coverage
    skip_install = true
    commands =
        coverage report
        coverage html

    [testenv:clean]
    deps = coverage
    skip_install = true
    commands = coverage erase

Depending on your project layout you might need extra configuration, see the working examples at
https://github.com/pytest-dev/pytest-cov/tree/master/examples for two common layouts.
