Open
Description
Bug report
Bug description:
Doctest does not recognize tests in the docstrings of methods decorated with functools.singledispatchmethod
. There's 2 causes:
- It checks the dictionary of classes for functions and subclasses, thereby not invoking descriptors.
Lines 1061 to 1073 in df4a2f5
functools.singledispatchmethod
does not callfunctools.update_wrapper
on its instance, only on the wrapper function returned from its__get__
method.
A similar issue for cached_property
was fixed in #107996.
Example
# mwe.py
import functools
class Class:
@functools.singledispatchmethod
def singledispatchmethod(self, arg):
"""
>>> print(Class().singledispatchmethod(5))
foo
"""
return "foo"
def regularmethod(self, arg):
"""
>>> print(Class().regularmethod(5))
foo
"""
return "foo"
$ python3 -m doctest -v mwe.py
Trying:
print(Class().regularmethod(5))
Expecting:
foo
ok
2 items had no tests:
mwe
mwe.Class
1 item passed all tests:
1 test in mwe.Class.regularmethod
1 test in 3 items.
1 passed.
Test passed.
doctest
only finds one doctest, where there should be two.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux