Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > doctest fails to see tests in decorated functions

Reply
Thread Tools

doctest fails to see tests in decorated functions

 
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-14-2009
I've just spotted a bug in doctest that it fails to see tests inside
decorated functions. It's been reported before:

http://bugs.python.org/issue1108

but the patch submitted doesn't work for me. I have a test script on the
page demonstrating the problem. Can anyone give me some clues as to a
work-around? I tried adding objects to __test__ but testmod() still failed
to pick up their tests.


if __name__ == '__main__':
import doctest
import types
__test__ = {}
allowed = [str, types.FunctionType,
types.ClassType, types.GeneratorType,
types.MethodType, types.UnboundMethodType]
for name in dir():
obj = vars()[name]
if type(obj) in allowed:
__test__[name] = obj
doctest.testmod()



--
Steven

 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-15-2009
Steven D'Aprano wrote:

> I've just spotted a bug in doctest that it fails to see tests inside
> decorated functions. It's been reported before:
>
> http://bugs.python.org/issue1108
>
> but the patch submitted doesn't work for me.


Never mind, it was a PEBCAK error. I failed to notice that applying a
decorator to a function shadows the functions docstring.

Normally I would use functools.wraps, but I am currently limping along on a
Python 2.4 installation here, which doesn't have it.


--
Steven

 
Reply With Quote
 
 
 
 
Michele Simionato
Guest
Posts: n/a
 
      02-15-2009
On Feb 15, 6:31*am, Steven D'Aprano <(E-Mail Removed)> wrote:
> Never mind, it was a PEBCAK error. I failed to notice that applying a
> decorator to a function shadows the functions docstring.
>
> Normally I would use functools.wraps, but I am currently limping along on a
> Python 2.4 installation here, which doesn't have it.


You may consider this: http://pypi.python.org/pypi/decorator

M.S.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
doctest.testfile fails on text files with Windows line endings Steven D'Aprano Python 1 04-11-2010 04:01 AM
doctest not seeing any of my doc tests Steven D'Aprano Python 3 09-07-2008 10:59 PM
What are decorated functions? Wolfgang Draxinger Python 4 08-23-2006 01:10 AM
doctest fails to NORMALIZE_WHITESPACE ? David MacKay Python 1 12-17-2005 10:00 AM
Constant.t fails 240 of 272 tests and recurs.t fails 1 of 25 tests on HPUX using perl 5.8.7 dayo Perl Misc 11 12-16-2005 09:09 PM



Advertisments