[TIP] testing class properties and internal methods

Jonathan Ballet jon at multani.info
Mon Mar 5 14:50:48 PST 2007


Le Mon, 5 Mar 2007 14:33:07 -0700,
"Nate Lowrie" <solodex2151 at gmail.com> a écrit :

> Just wondering what the thoughts were on this.....
> 
> I have never tested class properties since they are basically getter
> and setter functions.  I also never test getter and setter functions
> either.

When I use properties, I always declare them as "public methods". I
mean, like this :

class C(object):
    def getter_foo(self): pass
    def setter_foo(self, value): pass
    foo = property(fget=getter_foo, fset=setter_foo)

Like this, it's possible to test them outside the class.
I got some problems testing properties the "normal" way, so, I ended up
using something like that.

(try testing a setter which raises an exception, using property
syntax, for instance ;) )

 - Jonathan



More information about the testing-in-python mailing list