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


Groups > comp.lang.python > #19142

Re: verify the return value of a function

Date 2012-01-20 11:13 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: verify the return value of a function
References <CAOuJsM=DonsS_Th=XEx72z_5HjmdvdE4HOrJzmB4NuBt3fVSSw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4876.1327054447.27778.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: verify the return value of a function Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-01-20 11:13 +0100
  Re: verify the return value of a function Mel Wilson <mwilson@the-wire.com> - 2012-01-20 08:53 -0500
    Re: verify the return value of a function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-20 15:07 +0000
      Re: verify the return value of a function Terry Reedy <tjreedy@udel.edu> - 2012-01-20 15:42 -0500

csiph-web