]> granicus.if.org Git - python/commitdiff
Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa.
authorYury Selivanov <yselivanov@sprymix.com>
Mon, 8 Dec 2014 20:00:05 +0000 (15:00 -0500)
committerYury Selivanov <yselivanov@sprymix.com>
Mon, 8 Dec 2014 20:00:05 +0000 (15:00 -0500)
Lib/doctest.py
Lib/test/test_doctest.py
Misc/NEWS

index b2279524e14790a20d1dfcecccc65140f43d0cd3..bb9f43229d4f58c4c0548a1f0eabb9398aca91e5 100644 (file)
@@ -985,7 +985,8 @@ class DocTestFinder:
             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)
index 4b8d0d2b9c4596687c37c62d094bba5d59278fb1..95700a3d3f1a0d1f14db693dd34554118d336045 100644 (file)
@@ -4,6 +4,7 @@ Test script for doctest.
 
 from test import support
 import doctest
+import functools
 import os
 import sys
 
@@ -434,7 +435,7 @@ We'll simulate a __file__ attr that ends in pyc:
     >>> tests = finder.find(sample_func)
 
     >>> print(tests)  # doctest: +ELLIPSIS
-    [<DocTest sample_func from ...:18 (1 example)>]
+    [<DocTest sample_func from ...:19 (1 example)>]
 
 The exact name depends on how test_doctest was invoked, so allow for
 leading path components.
@@ -2364,6 +2365,22 @@ def test_trailing_space_in_test():
       foo \n
     """
 
+class Wrapper:
+    def __init__(self, func):
+        self.func = func
+        functools.update_wrapper(self, func)
+
+    def __call__(self, *args, **kwargs):
+        self.func(*args, **kwargs)
+
+@Wrapper
+def test_look_in_unwrapped():
+    """
+    Docstrings in wrapped functions must be detected as well.
+
+    >>> 'one other test'
+    'one other test'
+    """
 
 def test_unittest_reportflags():
     """Default unittest reporting flags can be set to control reporting
index d7c9a4919d15c0c41a139899e10330a73a8322aa..9ca0f1f1b1aabadf4230cd77d7bcbcce362f8364 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -194,6 +194,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #21740: Support wrapped callables in pydoc. Patch by Claudiu Popa.
+
 - Issue #23009: Make sure selectors.EpollSelecrtor.select() works when no
   FD is registered.