On Thu, Jan 19, 2012 at 12:45 PM, Jabba Laci <jabba.l...@gmail.com> 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?
<snip>
> 3) isinstance(return_value, cookielib.LWPCookieJar) seems to be the
> best way, however somewhere I read that using isinstance is
> discouraged

Explicit typechecking is often discouraged in favor of duck typing.
However, if you want to do explicit typechecking (as one might in unit
tests), then isinstance() is absolutely the technique to use.
The alternative would be to check for the specific attributes of
LWPCookieJar that you're relying upon (using hasattr() or similar),
but that's probably overkill here.

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to