The __module__ attribute is set, but the problem is the test in
doctest.py(DocTestFinder._from_module)

        ...
        elif inspect.isfunction(object):
            return module.__dict__ is object.func_globals
        elif inspect.isclass(object):
            return module.__name__ == object.__module__
        elif inspect.getmodule(object) is not None:
            return module is inspect.getmodule(object)

On 9/5/07, Michele Simionato <[EMAIL PROTECTED]> wrote:
>
> > En Tue, 04 Sep 2007 19:29:11 -0300, Daniel Larsson
> > <[EMAIL PROTECTED]> escribi?:
> >
> >
> >
> > > On 9/5/07, Ferenczi Viktor <[EMAIL PROTECTED]> wrote:
> >
> > >> > > @functools.wraps(f)
> > >> > > Pass the function to be wrapped by the decorator to the wraps
> > >> function.
> > >> > Ooops, right. That doesn't change the fact that decorated functions
> > >> get
> > >> > hidden from doctest though.
> >
> > > I have no issue when the decorator is defined in the same module as
> the
> > > decorated function, my problem is running doctests on functions using
> an
> > > imported decorator. Having to implement the decorator in every source
> > > module
> > > isn't very practical.
>
> I cannot reproduce your problem. Using functools.wraps
> the __module__ attribute is set correctly and everything
> works, even for decorators defined in separated modules.
> Care to post a complete example of what you are doing?


inspect.isfunction(object) returns true, but the function's func_globals
isn't the same as the module's __dict__, since the function is actually my
decorator wrapper function.

Here's my two files again:

# 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()



         Michele Simionato
>
> P.S. for some reason your messages are not appearing on
> Google groups, I see only the replies.
>
>
Weird... afraid I have no clue why not :)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to