Jabba Laci wrote:
Hi,

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'>

2) return_value.__class__ .__name__ gives 'LWPCookieJar', which is bettter

3) isinstance(return_value, cookielib.LWPCookieJar) seems to be the
best way, however somewhere I read that using isinstance is
discouraged

Thanks,

Laszlo
isinstance is fine, if you could find the source where it is discouraged... Could be a consequence of some specific context. However, checking types in OOP is in general a failure. Unitary tests are possibly an exception.

JM
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to