classification
Title: doctest.py should include method descriptors when looking inside a class __dict__
Type: feature request Stage: patch review
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, brian.curtin, daaku, georg.brandl, ncoghlan, stevenjd, terry.reedy
Priority: normal Keywords: needs review, patch

Created on 2008-10-04 00:13 by daaku, last changed 2010-07-18 21:36 by BreamoreBoy.

Files
File name Uploaded Description Edit Remove
patch stevenjd, 2010-02-07 00:44 patch to add support for method descriptors to doctest.DocTestFinder
doctest_test.py stevenjd, 2010-02-09 13:26
doctest_patch stevenjd, 2010-03-20 13:16 patch to add support for method descriptors to doctest.DocTestFinder, including updated test for test.test_doctest2
Messages (8)
msg74285 - (view) Author: (daaku) Date: 2008-10-04 00:13
doctest.py currently does not include doctests from method descriptors 
in a class.

The patch is simple, in the _find function in class DocTestFinder:

Original:
                # Recurse to methods, properties, and nested classes.
                if ((inspect.isfunction(val) or inspect.isclass(val) or
                      isinstance(val, property)) and
                      self._from_module(module, val)):

Patched:
                # Recurse to methods, properties, and nested classes.
                if ((inspect.isfunction(val) or inspect.isclass(val) or
                      inspect.ismethoddescriptor(val) or
                      isinstance(val, property)) and
                      self._from_module(module, val)):

Adding the "inspect.ismethoddescriptor(val) or" line.
msg98974 - (view) Author: Steven D'Aprano (stevenjd) Date: 2010-02-07 00:44
The patch you suggest is *not* sufficient, at least not by my testing.

However, the attached patch does work, according to my tests.
msg98983 - (view) Author: Terry J. Reedy (terry.reedy) Date: 2010-02-07 05:53
I am not sure whether this would be considered a bugfix or a new feature.
(ie, whether it would apply to 2.6 and 3.1 or not)

But the change is needed for 3.x also.

I am not sure whether the doc needs changing. A testcase should be added to doctest-test.
msg99115 - (view) Author: Steven D'Aprano (stevenjd) Date: 2010-02-09 13:26
Attached is a simple test script for the patch I submitted. I have tested it with Python 2.6 both before and after applying the patch. Run it from the command line.

With the unpatched doctest module, it prints:

"Expected 2 doctests, but only found 1"

After the patch, it finds and runs both doctests, and prints nothing.
msg99145 - (view) Author: Brian Curtin (brian.curtin) * Date: 2010-02-10 01:31
Can you add your test(s) in Lib/test/test_doctest.py ? That way it will be run with the Python regression suite. Ideally a documentation update would come with the patch. Also, line length should ideally be capped at 79 characters (re: PEP-8).

Might as well move the valname string building outside of both if-tests since it's common to both of them.


Terry: this looks like a feature rather than a bug, removing 2.6/3.1.
msg101372 - (view) Author: Steven D'Aprano (stevenjd) Date: 2010-03-20 13:16
I have fixed the issue with line length, and taken Brian's advice re valname. Updated patch for doctest and test.test_doctest2 is attached.
msg104300 - (view) Author: Georg Brandl (georg.brandl) Date: 2010-04-27 07:13
So for staticmethods and classmethods, valname doesn't need to be reassigned?
msg110690 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-07-18 21:36
Could someone please respond to Georg's comment msg104300, thanks.
History
Date User Action Args
2010-07-18 21:36:25BreamoreBoysetnosy: + BreamoreBoy
messages: + msg110690
2010-04-27 07:13:35georg.brandlsetnosy: + georg.brandl
messages: + msg104300
2010-03-20 13:16:47stevenjdsetfiles: + doctest_patch

messages: + msg101372
2010-02-11 12:40:53ncoghlansetnosy: + ncoghlan
2010-02-10 01:31:47brian.curtinset
nosy: + brian.curtin
versions: - Python 2.6, Python 3.1
messages: + msg99145
priority: normal
keywords: + patch, needs review
type: feature request
stage: patch review
2010-02-09 13:26:49stevenjdsetfiles: + doctest_test.py

messages: + msg99115
2010-02-07 05:53:03terry.reedysetnosy: + terry.reedy

messages: + msg98983
versions: + Python 3.1, Python 2.7, Python 3.2
2010-02-07 00:44:48stevenjdsetfiles: + patch
nosy: + stevenjd
messages: + msg98974

2008-10-04 00:13:25daakucreate