verify the return value of a function

Ian Kelly ian.g.kelly at
Fri Jan 20 10:30:22 EST 2012

On Fri, Jan 20, 2012 at 2:15 AM, Ulrich Eckhardt <
ulrich.eckhardt at> wrote:

> Am 19.01.2012 21:45, schrieb Jabba Laci:
>  In a unit test, I want to verify that a function returns a
>> cookielib.LWPCookieJar object. What is the correct way of doing that?
>> 1) First I tried to figure out its type with type(return_value) but it
>> is<type 'instance'>
> I'm not sure where the problem here is and where exactly you are seeing
> this. This might even indicate a problem with how the returned type is
> constructed.

This just means that LWPCookieJar is an old-style class:

>>> class Foo: pass
>>> type(Foo())
<type 'instance'>
>>> Foo().__class__
<class __main__.Foo at 0x01DC4CE0>

So for type checks here the __class__ attribute should be used, not the
type function.  isinstance is better for instance checks though in either

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list