doctest fails to see tests in decorated functions

Steven D'Aprano steve at pearwood.info
Sat Feb 14 02:19:17 EST 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




More information about the Python-list mailing list