Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19139
| References | <CAOuJsM=DonsS_Th=XEx72z_5HjmdvdE4HOrJzmB4NuBt3fVSSw@mail.gmail.com> |
|---|---|
| Date | 2012-01-19 13:13 -0800 |
| Subject | Re: verify the return value of a function |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4873.1327007605.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: verify the return value of a function Chris Rebert <clp2@rebertia.com> - 2012-01-19 13:13 -0800
csiph-web