doctest fails to see tests in decorated functions

Discussion in 'Python' started by Steven D'Aprano, Feb 14, 2009.

  1. 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
    Steven D'Aprano, Feb 14, 2009
    #1
    1. Advertising

  2. 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
    Steven D'Aprano, Feb 15, 2009
    #2
    1. Advertising

  3. On Feb 15, 6:31 am, Steven D'Aprano <> 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.
    Michele Simionato, Feb 15, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David MacKay

    doctest fails to NORMALIZE_WHITESPACE ?

    David MacKay, Dec 17, 2005, in forum: Python
    Replies:
    1
    Views:
    253
    Peter Otten
    Dec 17, 2005
  2. Wolfgang Draxinger

    What are decorated functions?

    Wolfgang Draxinger, Aug 22, 2006, in forum: Python
    Replies:
    4
    Views:
    326
    Richard Jones
    Aug 23, 2006
  3. Steven D'Aprano

    doctest not seeing any of my doc tests

    Steven D'Aprano, Sep 7, 2008, in forum: Python
    Replies:
    3
    Views:
    253
    Steven D'Aprano
    Sep 7, 2008
  4. Steven D'Aprano
    Replies:
    1
    Views:
    333
    Patrick Maupin
    Apr 11, 2010
  5. dayo
    Replies:
    11
    Views:
    325
    Ilya Zakharevich
    Dec 16, 2005
Loading...

Share This Page