Search code examples
pythontestingcode-coverage

Best way to measure code coverage for python without checking every imported module


I am in the process of trying to integrate code coverage into our development pipeline, and we are having a hard time using nosetest to accurately estimate our code coverage due to the fact that it also checks coverage for each of our imported libraries in our python packages. So we end up with code coverage percentages for things like import os, which is not allowing us to really see the data we want.

I have looked into using coverage.py, but that's in the very early stages.

I thought to ask if anyone else has had this issue and how they overcame it.

Thanks in advance!


Solution

  • Nosetests has an option to only produce coverage for named packages e.g.

    --cover-package=foo --cover-package=bar
    

    This is what I've done in the past.

    However, I moved over to pytest. I liked this better because it produced better error message, including dictionary diffs.