Search code examples
pythonpython-decoratorscoverage.py

Ignore deprecated methods with python coverage testing


I am doing some coverage analyis on a code base that contains a fair amount of deprecated (using the deprecated package) methods.

Most of these deprecated methods do not have any tests. So when doing a code coverage analysis (using coverage) these methods greatly pollute the results and make it hard to identify the important uncovered areas.

I know that I can manually add #pragma: no cover to these methods to ignore them. However, since they already have that decorator, I was curious if I could automatically filter these cases, for examply by using something similar to exclude_lines =...


Solution

  • You should be able to define exclude_lines with a regex that matches the decorator, and it will apply to the decorated function:

    [report]
    exclude_lines = 
        pragma: no cover
        @deprecated
    

    (etc...)