The doctest module seemed easy to implement so I decided to write a simpler version of it.my_doctest.pydef _doublets(lst):    for index, item in enumerate(lst[:-1]):        yield item, lst[index+1]def _test(tests):    for prev, curr in _doublets(tests.splitlines()):        if prev.strip().startswith('>>>'):            code = prev.replace('>>>','').strip()            if not eval(code) == eval(curr):                raise AssertionError({} should be {} but got {}.format(                    code, eval(curr.strip()), eval(code)))def doctest(func):    _test(func.__doc__)def testmod(module_name=None):    with open(module_name or __file__) as f:        _test(f.read())add.pyimport my_doctest as doctestdef add(a, b):        >>> add(1,3)    4    >>> add(2,5) # I should study more Math ...    8        return a + bdoctest.testmod()
Simplified doctest
python;unit testing;reinventing the wheel