def big(i,j):
'''
doctest:
>>> big(12,13)
13
'''
return i if i > j else j
if __name__ == '__main__':
import doctest
doctest.testmod()
$python test.py -v
Trying:
big(12,13)
Expecting:
13
ok
1 items had no tests:
__main__
1 items passed all tests:
1 tests in __main__.big
1 tests in 2 items.
1 passed and 0 failed.
Test passed.
#coding:utf-8
class Bird:
"""
doctest:
>>> bird = Bird('kula')
>>> bird.song()
'kula'
"""
def __init__(self,name):
self.name = name
def song(self):
return self.name
if __name__ == '__main__':
import doctest
doctest.testmod()
$python test.py -v
Trying:
bird = Bird('kula')
Expecting nothing
ok
Trying:
bird.song()
Expecting:
'kula'
ok
3 items had no tests:
__main__
__main__.Bird.__init__
__main__.Bird.song
1 items passed all tests:
2 tests in __main__.Bird
2 tests in 4 items.
2 passed and 0 failed.
Test passed.