Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make py.test --cov skip virtualenv directory

Should I care how my tests cover the external libraries I'm using in my project ?

The py.test --cov displays how all files are covered, including ones in my virtualenv directory. How can I make the output show only the coverage of the modules I've written ?

like image 289
David Ben Ari Avatar asked Jan 07 '16 09:01

David Ben Ari


People also ask

How do I ignore a file in pytest?

Ignore paths during test collectionThe --ignore-glob option allows to ignore test file paths based on Unix shell-style wildcards. If you want to exclude test-modules that end with _01.py , execute pytest with --ignore-glob='*_01.py' .

How do I run a pytest on a specific file?

Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .

What does pytest-COV do?

Once you have written test cases as required with Pytest, you can use Pytest-cov to run all the tests and report the coverage.


2 Answers

In the root of your project, create file .coveragerc containing:

[run] omit = path_to_libs_to_omit/* 

Depending on your setup, you might need to add --cov-config=path/to/.coveragerc as option to the py.test command.

There are more options you can use to configure coverage.

like image 144
sashk Avatar answered Sep 23 '22 11:09

sashk


You should add your module's name to the --cov command line option, for example form pytest-cov documentation:

py.test --cov=myproj tests/ 

This restrict the coverage to the module myproj and all its sub-modules.

like image 20
alexamici Avatar answered Sep 20 '22 11:09

alexamici