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.testmod does not run tests in functools.partial functions
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, jayvdb, steven.daprano, tim.peters, xtreak
Priority: normal Keywords:

Created on 2011-08-20 03:54 by steven.daprano, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
partial_doctest.py steven.daprano, 2011-08-20 03:54
Messages (3)
msg142512 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2011-08-20 03:54
Functions with docstrings which were created with partial are not run by doctest.testmod().

See the test script, which prints:

Expected 1 failure from 2 tests, but got 0 from 0.
msg221811 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-28 18:36
@Tim is this something you could take a look at please?
msg338678 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-03-23 14:37
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)
History
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56999
2019-03-23 14:37:45xtreaksetnosy: + xtreak

messages: + msg338678
versions: + Python 3.8, - Python 3.3
2019-02-24 22:23:49BreamoreBoysetnosy: - BreamoreBoy
2015-11-04 03:02:19jayvdbsetnosy: + jayvdb
2014-06-28 18:36:39BreamoreBoysetnosy: + BreamoreBoy, tim.peters
messages: + msg221811
2011-11-29 06:23:27ezio.melottisetcomponents: + Library (Lib)
stage: needs patch
2011-08-21 12:13:09eric.araujosetnosy: + eric.araujo
2011-08-20 03:54:32steven.dapranocreate