[New-bugs-announce] [issue1108] Problem with doctest and decorated functions

Daniel Larsson report at bugs.python.org
Wed Sep 5 12:53:25 CEST 2007

New submission from Daniel Larsson:

Seems like doctest won't recognize functions inside the module under
test are actually in that module, if the function is decorated by a
decorator that wraps the function in an externally defined function,
such as in this silly example:

# decorator.py
import functools

def simplelog(f):
    def new_f(*args, **kwds):
        print "Wrapper calling func"
        return f(*args, **kwds)
    return new_f

# test.py
from decorator import simplelog

def test():
    This test should fail, since the decorator prints output.
    Seems I don't get called though
    >>> test()
    return "works!"

if __name__ == '__main__':
    import doctest


The problem lies in DocTestFinder._from_module, which checks if the
function's func_globals attribute is the same as the module's __dict__

I'd propose to do the __module__/inspect.getmodule() checks (aren't they
 both checking the same thing btw?) before the inspect.isfunction check.

components: Library (Lib)
messages: 55660
nosy: danilo
severity: normal
status: open
title: Problem with doctest and decorated functions
type: behavior
versions: Python 2.5

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list