doctests and decorators

Michele Simionato michele.simionato at gmail.com
Tue Jun 16 19:24:39 CEST 2009


On Jun 16, 6:39 pm, Eric Snow <es... at verio.net> wrote:
> On Jun 16, 10:31 am, Christian Heimes <li... at cheimes.de> wrote:
>
>
>
> > Eric Snow schrieb:
>
> > > Apparently there is a known issue with doctests, in which tests in
> > > functions using externally defined decorators are ignored.  The
> > > recommended fix is to update the order of checks in the _from_module
> > > method of DocTestFinder in the doctest module.  The bug and fix are
> > > discussed at the following URLs (and several places in this group):
>
> > >http://bugs.python.org/issue1108
> > >http://mail.python.org/pipermail/python-list/2007-September/627866.html
>
> > > The fix implies that the inpect.getmodule function will find the
> > > module of the function object and not of the decorator.  However, in
> > > 2.4 the inspect.getmodule function returns the module of the
> > > decorator.  I have subsequently tested this in 2.5 and 2.6, and it
> > > also returns the module of the decorator.  As such, the fix for
> > > doctests does not work in my tests.  Below is the test code that I
> > > used:
>
> > It's not an issue with the doctest module but with your code. You want
> > to use functools.wraps().
>
> >http://docs.python.org/library/functools.html#functools.wraps
>
> > Christian
>
> Unfortunately, I am stuck on 2.4 for now, which does not have the
> functools.
>
> -eric

But you can always use the decorator module: http://pypi.python.org/pypi/decorator



More information about the Python-list mailing list