Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

determining test coverage with py.test + gevent

How can one get an accurate test coverage report when using py.test + gevent?

I've already tried the obvious thing, using the pytest-cov plugin for py.test, but it generates inaccurate reports when gevent is in use.

like image 360
kkurian Avatar asked Apr 06 '14 06:04

kkurian


People also ask

How do you increase code coverage in Python?

Increase coverage by adding more tests The code coverage has increased to 78% on adding another test case. It can be increased further to 100% in a similar fashion.

What is BrPart coverage?

The output tells us that in example. lib we have one partial branch (BrPart) which reduces the coverage in that module to 86% in this case.


1 Answers

The gevent coverage issue was fixed in coveragepy recently.

However, pytest-cov fails to run with coverage>=4.

One possible fix, is to run py.test with the later versions of coverage.py without using the pytest-cov plugin.

First, install coverage >= 4 and uninstall the pytest-cov plugin:

pip install --pre --upgrade coverage
pip uninstall pytest-cov

Add the following setting to .coveragerc:

[run]
concurrency = gevent

Then run with:

coverage run -m py.test

(instead of the regular py.test run)

like image 144
yprez Avatar answered Sep 28 '22 06:09

yprez