Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19139 > unrolled thread

Re: verify the return value of a function

Started byChris Rebert <clp2@rebertia.com>
First post2012-01-19 13:13 -0800
Last post2012-01-19 13:13 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: verify the return value of a function Chris Rebert <clp2@rebertia.com> - 2012-01-19 13:13 -0800

#19139 — Re: verify the return value of a function

FromChris Rebert <clp2@rebertia.com>
Date2012-01-19 13:13 -0800
SubjectRe: verify the return value of a function
Message-ID<mailman.4873.1327007605.27778.python-list@python.org>
On Thu, Jan 19, 2012 at 12:45 PM, Jabba Laci <jabba.laci@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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web