简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM