Python: using doctests for classes

Posted by Adam Matan on Stack Overflow See other posts from Stack Overflow or by Adam Matan
Published on 2010-04-25T12:24:25Z Indexed on 2010/04/25 12:33 UTC
Read the original article Hit count: 322

Filed under:
|
|

Hi,

Is it possible to use Python's doctest concept for classes, not just functions?

If so, where shall I put the doctests - at the class' docstring, or at the constructor's docstring?

To clarify, I'm looking for something like:

class Test:
    """
    >>> a=Test(5)
    >>> a.multiply_by_2()
    10
    """
    def __init__(self, number):
        self._number=number

    def multiply_by_2(self):
        return self._number*2

Thanks in advance,

Adam

© Stack Overflow or respective owner

Related posts about python

Related posts about doctest