This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: doctest doesn't find nested functions
Type: behavior Stage: patch review
Components: Tests Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: danb37, jayvdb, pjdelport, r.david.murray, tim.peters, zseil
Priority: normal Keywords: patch

Created on 2007-02-01 19:20 by danb37, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
doctest_nested_functions.diff zseil, 2007-03-17 00:37 patch against trunk revision 54419 review
doctest_nested_functions-py3.6.diff jayvdb, 2015-11-08 06:22 Ziga's patch amended version for Python 3.6 review
doctest_nested_functions-py3.6.diff jayvdb, 2015-11-08 07:58 Python 3.6-remove unnecessary if clause review
Messages (4)
msg51831 - (view) Author: Daniel Brown (danb37) Date: 2007-02-01 19:20
If a nested function has doctests, they won't be run:
{{{
def f():
  '''
  >>> 'a'
  'a'
  '''

  def g():
    '''
    >>> 'a'
    'b'
    '''
    pass

  pass
}}}

DocTestFinder will only find f's doctest and won't recurse to find g's, surprising the programmer when they (hopefully) discover that their inner doctest is incorrect!
msg51832 - (view) Author: Piet Delport (pjdelport) Date: 2007-03-16 20:44
DocTestFinder uses object inspection to find docstrings, which doesn't really allow this kind of thing:  g isn't created until f is actually run.

Making this possible would probably require implementing an alternate doctest finder based on source code inspection (via the new _ast module?).
msg51833 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) Date: 2007-03-17 00:37
Here is a patch that implements this new functionality.
I don't know how desireable this feature is, I just
wanted to see if it could be done.
File Added: doctest_nested_functions.diff
msg110519 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-16 22:32
I believe that there could be interest in this, has anyone taken over doctest from tim_one?
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44538
2015-11-08 07:58:46jayvdbsetfiles: + doctest_nested_functions-py3.6.diff
2015-11-08 06:22:59jayvdbsetfiles: + doctest_nested_functions-py3.6.diff
versions: + Python 3.4, Python 3.5, Python 3.6, - Python 3.1, Python 3.2
2015-11-04 02:57:57jayvdbsetnosy: + jayvdb
2014-04-15 14:41:45r.david.murraysetnosy: + r.david.murray
2014-02-03 19:20:58BreamoreBoysetnosy: - BreamoreBoy
2010-07-16 22:32:20BreamoreBoysetversions: + Python 3.2
nosy: + BreamoreBoy

messages: + msg110519

assignee: tim.peters ->
type: performance -> behavior
2009-03-30 20:52:47ajaksu2setstage: patch review
type: performance
components: + Tests, - None
versions: + Python 3.1, Python 2.7, - Python 2.5
2007-02-01 19:20:32danb37create