Slide 10
Slide 10 text
Testing as Documentation (DocTest)
1. Unit Tests expressed as doc-strings can
be used as documentation.
2. Unit Tests expressed as doc-strings can
be used as unit tests
def my_function(a, b):
"""
>>> my_function(2, 3)
6
>>> my_function('a', 3)
'aaa'
"""
return a * b
Trying:
my_function(2, 3)
Expecting:
6
ok
Trying:
my_function('a', 3)
Expecting:
'aaa'
ok
1 items had no tests:
doctest_simple_with_docs
1 items passed all tests:
2 tests in doctest_simple_with_docs.my_function
2 tests in 2 items.
2 passed and 0 failed.
Test passed.