Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding abstractproperties from coverage reports

I have an abstract base class along the lines of:

class MyAbstractClass(object):     __metaclass__ = ABCMeta      @abstractproperty     def myproperty(self): pass 

But when I run nosetests (which coverage) on my project, it complains that the property def line is untested. It can't actually be tested (AFAIK) as instantiation of the abstract class will result in an exception being raised..

Are there any workarounds to this, or do I just have to accept < 100% test coverage?

Of course, I could remove the ABCMeta usage and simply have the base class raise NotImpementedError, but I prefer the former method.

like image 888
Demian Brecht Avatar asked Feb 08 '12 22:02

Demian Brecht


1 Answers

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. """ 
like image 93
kouk Avatar answered Sep 19 '22 02:09

kouk