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

Terry Reedy tjreedy at udel.edu
Thu Oct 18 21:31:19 EDT 2012


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




More information about the Python-list mailing list