File: tox.rst

package info (click to toggle)
python-pytest-cov 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: python: 2,338; makefile: 6
file content (73 lines) | stat: -rw-r--r-- 1,728 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
===
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.