简体   繁体   中英

How to obtain aggregated coverage per subpackage from pytest-cov?

I'm using pytest in combination with the pytest-cov plugin on a large code base. In general I'm aware of the various output report generators and the html output offers great value when analyzing coverage information on a low-level, ie, when looking into individual files and their particular line coverage.

I'm also aware of the "grand total" coverage that pytest reports, which is of course aggregated over the entire project.

When I haven't figured out though is how to obtain coverage information in between the grand total and file level. Let's say the top level package name is foo and it contains thousands of files structured into various (sometimes deeply nested) sub-packages. During development of a certain subpackage say foo.bar.baz (which may be ~hundred files large itself), it would be very useful if I could obtain a coverage specifically for foo.bar.baz . Unfortunately, the "file level" reporting doesn't help in that case, because mentally aggregating all the files in foo.bar.baz is almost impossible.

Is there an easy way to obtain the coverage on a per sub-package basis?

You can get the data in JSON form (using coverage json ), and then post-process it yourself. coverage.py doesn't have a way to do it.

An example of doing this is goals.py which offers limits and checks on subsets of your files. Maybe it can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM