[issue12790] doctest.testmod does not run tests in functools.partial functions

Karthikeyan Singaravelan report at bugs.python.org
Sat Mar 23 10:37:45 EDT 2019


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

functools.partial returns a partial object and detecting partials is not handled inside the finder when given a module. Perhaps partials could be handled as a special case to detect tests in them?

diff --git a/Lib/doctest.py b/Lib/doctest.py
index 79d91a040c..aeff913c9a 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -95,6 +95,7 @@ __all__ = [
 import __future__
 import difflib
 import inspect
+import functools
 import linecache
 import os
 import pdb
@@ -962,6 +963,8 @@ class DocTestFinder:
             return module.__name__ == object.__module__
         elif isinstance(object, property):
             return True # [XX] no way not be sure.
+        elif isinstance(object, functools.partial):
+            return True
         else:
             raise ValueError("object must be a class or function")
 
@@ -989,7 +992,8 @@ class DocTestFinder:
                 valname = '%s.%s' % (name, valname)
                 # Recurse to functions & classes.
                 if ((inspect.isroutine(inspect.unwrap(val))
-                     or inspect.isclass(val)) and
+                     or inspect.isclass(val)
+                     or isinstance(val, functools.partial)) and
                     self._from_module(module, val)):
                     self._find(tests, val, valname, module, source_lines,
                                globs, seen)

----------
nosy: +xtreak
versions: +Python 3.8 -Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue12790>
_______________________________________


More information about the Python-bugs-list mailing list