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):
    @functools.wraps(f)
    def new_f(*args, **kwds):
        print "Wrapper calling func"
        return f(*args, **kwds)
    return new_f

# test.py
from decorator import simplelog

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

if __name__ == '__main__':
    import doctest
    doctest.testmod()

--

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

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 <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1108>
__________________________________
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to