Python Tutorial

Thursday, April 25, 2013

Doctest in python

The doctest module searches for pieces of text that look like interactive Python sessions in docstrings, and then executes those sessions to verify that they work exactly as shown. If test failed it will shows proper message.

def myfun(a, b):
    """
    >>> myfun(2,3)
    5
    >>> myfun(4,3)
    7
    """
    return a+b


if __name__ == '__main__':
    import doctest
    doctest.testmod()

0 comments:

Post a Comment