homepage

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.py should include method descriptors when looking inside a class __dict__
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brian.curtin, daaku, filip.zyzniewski, georg.brandl, ncoghlan, r.david.murray, steven.daprano, terry.reedy
Priority: normal Keywords: needs review, patch

Created on 2008年10月04日 00:13 by daaku, last changed 2022年04月11日 14:56 by admin.

Files
File name Uploaded Description Edit
patch steven.daprano, 2010年02月07日 00:44 patch to add support for method descriptors to doctest.DocTestFinder
doctest_test.py steven.daprano, 2010年02月09日 13:26
doctest_patch steven.daprano, 2010年03月20日 13:16 patch to add support for method descriptors to doctest.DocTestFinder, including updated test for test.test_doctest2
Messages (9)
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 (steven.daprano) * (Python committer) 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) * (Python committer) 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 (steven.daprano) * (Python committer) 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) * (Python committer) 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 (steven.daprano) * (Python committer) 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) * (Python committer) 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.
msg205905 - (view) Author: Filip Zyzniewski (filip.zyzniewski) Date: 2013年12月11日 13:25
It seems like there is also an issue with property classes defined in a different module.
In the example below Foo.x uses standard property, and Foo.y uses prop imported from the prop module.
This results in docstring for Foo.y to be missed:
filip@klocek:~/test$ cat prop.py
class prop(property):
 pass
filip@klocek:~/test$ cat foo.py
from prop import prop
class Foo(object):
 @property
 def x(self):
 """
 >>> Foo().x
 'x'
 """
 return 'x'
 @prop
 def y(self):
 """
 >>> Foo().y
 'y'
 """
 return 'y'
filip@klocek:~/test$ python --version
Python 2.7.3
filip@klocek:~/test$ python -m doctest foo.py -v
Trying:
 Foo().x
Expecting:
 'x'
ok
2 items had no tests:
 foo
 foo.Foo
1 items passed all tests:
 1 tests in foo.Foo.x
1 tests in 3 items.
1 passed and 0 failed.
Test passed.
filip@klocek:~/test$ python3 --version
Python 3.2.3
filip@klocek:~/test$ python3 -m doctest foo.py -v
Trying:
 Foo().x
Expecting:
 'x'
ok
2 items had no tests:
 foo
 foo.Foo
1 items passed all tests:
 1 tests in foo.Foo.x
1 tests in 3 items.
1 passed and 0 failed.
Test passed.
filip@klocek:~/test$
History
Date User Action Args
2022年04月11日 14:56:40adminsetgithub: 48287
2014年02月03日 15:42:56BreamoreBoysetnosy: - BreamoreBoy
2013年12月11日 14:02:17r.david.murraysetnosy: + r.david.murray
2013年12月11日 13:25:49filip.zyzniewskisetnosy: + filip.zyzniewski
messages: + msg205905
2010年11月12日 05:33:12terry.reedysetversions: - Python 2.7
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:47steven.dapranosetfiles: + doctest_patch

messages: + msg101372
2010年02月11日 12:40:53ncoghlansetnosy: + ncoghlan
2010年02月10日 01:31:47brian.curtinsetpriority: normal

type: enhancement
versions: - Python 2.6, Python 3.1
keywords: + patch, needs review
nosy: + brian.curtin

messages: + msg99145
stage: patch review
2010年02月09日 13:26:49steven.dapranosetfiles: + 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:48steven.dapranosetfiles: + patch
nosy: + steven.daprano
messages: + msg98974

2008年10月04日 00:13:25daakucreate

AltStyle によって変換されたページ (->オリジナル) /