[PYTHON] Create documentation and test code using doctest.testfile ()

I felt that doctest.testfile () would be useful, so make a note

dcotest.testmod () is testing the example in the comments in the source code I thought this was also useful, but I tend to get a lot of comments

example.txt


Example of hoge
 python hoge.py -v
=========================

adder() receives two arguments and returns
the sum of them

 >>> from hoge import adder
 >>> adder(1, 2)
 3
 >>> adder('doc', 'test')
 'doctest'

hoge.py


import doctest

def adder(a, b):
    return a + b

if __name__ == "__main__":
    doctest.testfile('./example.txt')

Recommended Posts

Create documentation and test code using doctest.testfile ()
python setup.py test the code using multiprocess
Distribution and test
Create a web map using Python and GDAL
Create a Mac app using py2app and Python3! !!
Create a color sensor using a Raspberry Pi and a camera
Create dummy data using Python's NumPy and Faker packages
Strengthen with code test ⑦
Strengthen with code test ③
Strengthen with code test ⑤
Strengthen with code test ④
Strengthen with code test ②
[Memo] Test code summary
Strengthen with code test ①
Strengthen with code test ⑧
Strengthen with code test ⑨
Create code that outputs "A and pretending B" in python