<br><br><div><span class="gmail_quote">On 9/5/07, <b class="gmail_sendername">Gabriel Genellina</b> <<a href="mailto:gagsl-py2@yahoo.com.ar">gagsl-py2@yahoo.com.ar</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
En Tue, 04 Sep 2007 19:29:11 -0300, Daniel Larsson<br><<a href="mailto:daniel.j.larsson@gmail.com">daniel.j.larsson@gmail.com</a>> escribi�:<br><br>> On 9/5/07, Ferenczi Viktor <<a href="mailto:python@cx.hu">python@cx.hu
</a>> wrote:<br>>><br>>> > > @functools.wraps(f)<br>>> > > Pass the function to be wrapped by the decorator to the wraps<br>>> function.<br>>> > Ooops, right. That doesn't change the fact that decorated functions
<br>>> get<br>>> > hidden from doctest though.<br>><br>><br>> I have no issue when the decorator is defined in the same module as the<br>> decorated function, my problem is running doctests on functions using an
<br>> imported decorator. Having to implement the decorator in every source<br>> module<br>> isn't very practical. Try splitting your module in two, as I did, and run<br>> with -v, and you'll see the problem.
<br><br>Looks like a bug. doctest is failing to recognize that the decorated<br>function belongs to the module being tested.<br><br>A simple patch: In doctest.py, method _from_module, near line 840, you<br>have these lines:
<br><br>         elif inspect.getmodule(object) is not None:<br>             return module is inspect.getmodule(object)<br><br>Move them up, just before the line:<br><br>         elif inspect.isfunction(object):</blockquote>
<div><br>Yes, that was basically what I did as well. It makes much more sense to check __module__ first (which is modifiable) rather than func_globals (which obviously isn't). <br><br>I would have guessed the inspect.getmodule
 check would cover the isclass test as well (?)<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">This works fine in this case, but I'm not sure whether this breaks in
<br>other circumstances (but I can't think of a case when using<br>inspect.getmodule() would not be appropiate).<br><br>PS: I can't see any tests for decorated functions (except<br>@classmethod/@staticmethod) in the library test suite. I'll try to add
<br>some and submit a patch.<br><br>--<br>Gabriel Genellina<br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a></blockquote></div><br>