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


Groups > comp.lang.python > #31704

Re: Add if...else... switch to doctest?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Add if...else... switch to doctest?
Date 2012-10-18 21:31 -0400
References <c500a76c-3e6b-4dfc-97ca-8b24f0628620@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2489.1350610506.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 10/18/2012 8:08 PM, David wrote:
> Hello, how to add if...else... switch to doctest?
> E.g. function outputs different value when global_var change.
>
> """
> if (global_var == True):
>>>> function()
> [1,2]
> else:
>>>> function()
> [1,2,3]
> """

doctests should/must be self contained. IE, you would have to set the 
'global_var' in the doctext code itself.

 >>> def function():
...   if global_var: return [1,2]
...   else: return [1,2,3]
 >>> global_var = True
 >>>function()
[1,2]
 >>> global_var = False
 >>> function()
[1,2,3]

-- 
Terry Jan Reedy

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


Thread

Add if...else...  switch to doctest? David <zhushenli@gmail.com> - 2012-10-18 17:08 -0700
  Re: Add if...else...  switch to doctest? Ben Finney <ben+python@benfinney.id.au> - 2012-10-19 12:29 +1100
  Re: Add if...else...  switch to doctest? Terry Reedy <tjreedy@udel.edu> - 2012-10-18 21:31 -0400
  Re: Add if...else...  switch to doctest? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-19 01:57 +0000
  Re: Add if...else...  switch to doctest? Duncan Booth <duncan.booth@invalid.invalid> - 2012-10-19 09:27 +0000

csiph-web