Excluding abstractproperties from coverage reports
For me the best solution was what @Wesley mentioned in his comment to the accepted answer, specifically replacing 'pass' with a docstring for the abstract property, e.g.:
class MyAbstractClass(object): __metaclass__ = ABCMeta @abstractproperty def myproperty(self): """ this property is too abstract to understand. """
There's no way to exclude the abstract properties precisely as you have it, but if you make a slight change, you can. Have your abstract property raise an error:
@abstractpropertydef myproperty(self): raise NotImplementedError
Then you can instruct coverage.py to ignore lines that raise NotImplementedError. Create a .coveragerc file, and in it put:
[report]exclude_lines = # Have to re-enable the standard pragma pragma: no cover # Don't complain if tests don't hit defensive assertion code: raise NotImplementedError
For more ideas about the kinds of lines you might want to always ignore, see: http://nedbatchelder.com/code/coverage/config.html
I have custom skip logic in my .coveragerc
:
[report]exclude_lines = pragma: no cover @abstract
This way all abstractmethods and abstractproperties are marked as skipped.