Doctests for nested functions

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Sep 22 20:52:54 EDT 2006


Recently I have posted this same question on it.comp.lang.python, maybe
there aren't solutions, but I'd like to know what you think.

Can doctests be added to nested functions too? (This can be useful to
me, I use nested function when I don't have attributes that I have to
remember, but I want to split the logic in some subparts anyway).
Example:

def foo():
  """
  >>> foo()
  21
  """
  def bar():
    """
    >>> bar()
    11
    """
    print 10
  print 20
import doctest
doctest.testmod()

Bye,
bearophile




More information about the Python-list mailing list