[issue21740] doctest doesn't allow duck-typing callables

Claudiu Popa report at bugs.python.org
Fri Jun 20 10:08:56 CEST 2014


Claudiu Popa added the comment:

How about using this?

diff -r 1e74350dd056 Lib/doctest.py
--- a/Lib/doctest.py    Tue Jun 17 22:27:46 2014 -0500
+++ b/Lib/doctest.py    Fri Jun 20 11:08:00 2014 +0300
@@ -984,7 +984,8 @@
             for valname, val in obj.__dict__.items():
                 valname = '%s.%s' % (name, valname)
                 # Recurse to functions & classes.
-                if ((inspect.isroutine(val) or inspect.isclass(val)) and
+
+                if ((inspect.isroutine(inspect.unwrap(val)) or inspect.isclass(val)) and
                     self._from_module(module, val)):
                     self._find(tests, val, valname, module, source_lines,
                                globs, seen)

This seems to work for the given example and if the decorator uses update_wrapper or @wraps.

----------
nosy: +Claudiu.Popa

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21740>
_______________________________________


More information about the Python-bugs-list mailing list