How to configure coverage with tox?
Asked Answered
E

1

6

I am using tox to run tests on different envs using tox -p(run in parallel), but have a problem with coverage report generation for all tests.

tox.ini:

[tox]
envlist = env1,ev2,report
skipsdist=True

[base]
deps = pytest


[testenv:env1]
deps = custom-package-1
       {[base]deps}
commands = pytest --cov-append tests/flows/test_1.py

[testenv:env2]
deps = custom-package-2
       {[base]deps}
commands = pytest --cov-append tests/flows/test_2.py

[testenv:report]
deps = coverage[toml]
commands = coverage report
depends = env1,env2
parallel_show_output = true

pyproject.toml coverage section:

[tool.coverage.report]
fail_under = 100
show_missing = true
exclude_lines = [
    'pragma: no cover',
    '\.\.\.',
    'if TYPE_CHECKING:',
    "if __name__ == '__main__':",
]

Error:

No source for code: '/Users/my_user/projects/my_proect/flows/__init__.py'.

Can someone tell me what is wrong with provided configuration?

Effort answered 10/12, 2021 at 18:4 Comment(0)
J
1

You need to remap the source files see https://coverage.readthedocs.io/en/6.2/config.html?highlight=paths#paths and for example https://github.com/tox-dev/tox/blob/master/tox.ini#L136-L143

Jurat answered 10/12, 2021 at 18:22 Comment(2)
Paths specify where to search for coverage information?And config is fine?Effort
Paths specify how to map the source files from the site-packages folder (installed files)t to the source files. The error could also be a sign of some files deleted but not yet removed from as-installed vs local source tree.Jurat

© 2022 - 2024 — McMap. All rights reserved.