doctest fails to see tests in decorated functions

S

Steven D'Aprano

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

Steven D'Aprano

Steven said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top