Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measure Unit Test coverage of specific files with Py.Test

I'm trying to retrieve the coverage of my unittests with Py.Test. The problem is that I get also coverage information about other python files which I don't care about.

Here is an example of my file structure. In this case I want to test: car.py, wheel.py and steer.py

python2.7/site-packages/

  • car.py
  • wheel.py
  • steer.py
  • coverage.py (from pypi.python.org)
  • yaml (the python yaml library, from pypi.python.org)
  • pytest-2.5.2-py2.7.egg (the python py.test library)
  • and many more

python2.7/site-packages/test/

  • test_car.py
  • conftest.py

Now I use Py.Test to execute the test:

python -m pytest --cov python2.7/site-packages/ python2.7/site-packages/test/test_car.py

But this results in the coverage of all the python files in site-packages (kinda obvious).

python -m pytest --cov python2.7/site-packages/car.py python2.7/site-packages/test/test_car.py

This results in only the coverage of the car.py and not all the files I want.

How can I use Py.Test to only to measure coverage of specific files?

(I also tried:

python -m pytest --cov python2.7/site-packages/car.py,python2.7/site-packages/wheel.py python2.7/site-packages/test/test_car.py

But Py.Test doesn't know how to parse and use this argument. )

like image 499
RvdK Avatar asked Apr 02 '14 08:04

RvdK


1 Answers

I found the solution. You can supply multiple --cov file arguments.

python -m pytest \
  --cov python2.7/site-packages/car.py \
  --cov python2.7/site-packages/wheel.py \
  --cov python2.7/site-packages/steer.py \
  python2.7/site-packages/test/test_car.py
like image 64
RvdK Avatar answered Sep 21 '22 02:09

RvdK