Conditional coverage based on any rules you define!
Slowing down. Last release over 3 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install coverage-conditional-plugincoverage-conditional-plugin
Conditional coverage based on any rules you define!
Some projects have different parts that relies on different environments:
- Python version, some code is only executed on specific versions and ignored on others
- OS version, some code might be Windows, Mac, or Linux only
- External packages, some code is only executed when some 3rd party package is installed
Current best practice is to use # pragma: no cover for this places in our project.
This project allows to use configurable pragmas
that include code to the coverage if some condition evaluates to true,
and fallback to ignoring this code when condition is false.
Read the announcing post.
Installation
pip install coverage-conditional-plugin
Then you will need to add to your setup.cfg or .coveragerc file
some extra configuration:
[coverage:run]
# Here we specify plugins for coverage to be used:
plugins =
coverage_conditional_plugin
[coverage:coverage_conditional_plugin]
# Here we specify files to conditionally omit:
omit =
"sys_platform == 'win32'":
"my_project/omit*.py"
"my_project/win.py"
# Here we specify our pragma rules:
rules =
"sys_version_info >= (3, 8)": py-gte-38
"is_installed('mypy')": has-mypy