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/
python2.7/site-packages/test/
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. )
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With