is there any way to doctest locally defined functions? As an example I would want
def foo():
  """ >>> foo()
  testfoo"""
  def foo2():
    """ >>> 1/0 """ 
    print 'testfoo'
  foo2()
to NOT pass the test. But still I would not want to make foo2 global for the entire module...
Thanks. I already feared there would be no way around code outside the docstring. Still I thought there might be a trick to import the locals of a function and thus get access to nested functions. Anyhow, a solution using Alex' approach would read
def foo(debug=False):
  """
     >>> foo()
     testfoo
     >>> foo(debug=True)
     """
  def foo2():
    """
       >>> 1/0"""
    print 'testfoo'
  if debug :
    import doctest
    for f in [foo2]: doctest.run_docstring_examples(f,locals())
  foo2()
Now the only question is how to automate this approach, so one has something like
for f in locals().values(): doctest.run_docstring_examples(f,locals())
but without the imported and built in functions and variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With