Author danilo
Recipients danilo
Date 2007-09-05.10:53:23
SpamBayes Score 0.00103886
Marked as misclassified No
Message-id <1188989604.95.0.0786142357028.issue1108@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2007-09-05 10:53:25danilosetspambayes_score: 0.00103886 -> 0.00103886
recipients: + danilo
2007-09-05 10:53:24danilosetspambayes_score: 0.00103886 -> 0.00103886
messageid: <1188989604.95.0.0786142357028.issue1108@psf.upfronthosting.co.za>
2007-09-05 10:53:24danilolinkissue1108 messages
2007-09-05 10:53:23danilocreate