Search code examples
pythonpython-3.xpytestcoverage.pypytest-cov

pytest-cov functionality for package specific coverage thresholds


I am using pytest-cov for coverage checks on my repo. Is there a functionality by which I can specify coverage thresholds for a specific package/packages within a repository? Currently my coverage condition uses --cov-fail-under to fail if the overall coverage falls below the specified threshold. Say I have a directory structure as follows(Just an example)

/src
|-- Module1
|-- Pkg1
|-- Pkg2
|   `-- Module2
|-- Pkg3
|-- Pkg4
|   |-- Module3
|   |-- Module4
|   |-- Pkg5
|   |   |-- Module5
|   |   |-- Module6
|   |   `-- Module7
|   `-- Pkg6
|-- Pkg7
`-- Pkg8

In this kind of a hypothetical scenario, I would like to specify thresholds for Pkg4, Pkg5 and Pkg7. Also in such a case calculations for Pkg5 would not be included in those of Pkg 4. I know that I can generate a coverage report and implement this but just wanted to confirm if there is a way to do this out of the box


Solution

  • There isn't a feature like this in coverage.py (on which pytest-cov is built).