For pytest with pytest-cov: how to specify parallel=True for coverage version >= 5
Asked Answered
F

1

6

In pytest-cov documentation it says:

Note that this plugin controls some options and setting the option in the config file will have no effect. These include specifying source to be measured (source option) and all data file handling (data_file and parallel options).

However it doesn't say how to change these options. Is there a way to change it (parallel=True)? I want to change this because after coverage is upgraded from < 5 to latest (5.1) I got these:

Failed to generate report: Couldn't use data file '/path/to/jenkins/workspace/pr/or/branch/.coverage': no such table: line_bits

Note: using coverage < 5 do not have this problem

I have also tried adding .coveragerc with the following but still get the same issue.

[run]
parallel = True

The way it is run in jenkins:

pytest ./tests --mpl -n 4 \
   --junitxml=pyTests.xml --log-cli-level=DEBUG -s \
   --cov=. --cov-report --cov-report html:coverage-reports
Fug answered 12/5, 2020 at 18:15 Comment(1)
This also seems to be a problem when using unittest, not just pytest.Distiller
O
4

This is due to pytest-cov using coverage combine, which combines all coverage results: In parallel it mixes results from other runs, that may or may not be completed, and in any cases are irrelevant.

I think if you're having the issue, it may be because you're running multiple tests in parallel, like multiple versions of Python.

In which case it's easily solved by specifying a unique COVERAGE_FILE for each run, like:

export COVERAGE_FILE=.coverage.3.7

for the Python 3.7 run, an so on.

See: https://github.com/nedbat/coveragepy/issues/883#issuecomment-650562896

Overturn answered 27/6, 2020 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.