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 ?
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' .
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 .
Once you have written test cases as required with Pytest, you can use Pytest-cov to run all the tests and report the coverage.
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.
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.
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