Doctests and decorated methods don't get along
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Feb 6 18:58:07 EST 2010
On Sat, 06 Feb 2010 14:39:00 -0500, Terry Reedy wrote:
> On 2/6/2010 6:48 AM, Steven D'Aprano wrote:
>> It seems that doctest doesn't discover or execute doctests in methods
>> which have been decorated.
[...]
> Doctest has to scan the dict, so it does not see the attribute-lookup
> result.
Ahaha, now we're getting somewhere. If I do this:
>>> import inspect
>>> import test_doctests
>>> method3 = test_doctests.Test.__dict__['method3']
>>> inspect.isfunction(method3)
False
>>> inspect.ismethod(method3)
False
But:
>>> inspect.ismethoddescriptor(method3)
True
which is what I want to see. Presumably doctest.DocTestFinder needs a
patch to call methoddescriptor's __get__ method.
(BTW, classmethod, staticmethod and property are all special-cased by
DocTestFinder.)
--
Steven
More information about the Python-list
mailing list