Doctests#
[1]:
import doctest
def add(a, b):
"""
This is a test:
>>> add(7,6)
13
"""
return a + b
doctest.testmod(verbose=True)
Trying:
add(7,6)
Expecting:
13
ok
1 items had no tests:
__main__
1 items passed all tests:
1 tests in __main__.add
1 tests in 2 items.
1 passed and 0 failed.
Test passed.
[1]:
TestResults(failed=0, attempted=1)
Debugging#
[2]:
doctest.testmod()
def multiply(a, b):
"""
This is a test:
>>> multiply(2, 2)
5
"""
import pdb
pdb.set_trace()
return a * b
import pdb
imports the Python debuggerpdb.set_trace()
creates a breakpoint that starts the Python debugger.
See also: