6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

doctest.testfile()を使ってドキュメント兼テストコードを作成

6
Posted at

doctest.testfile()が便利そうな気がしたのでメモ

dcotest.testmod()はソースコード中のコメントにある例をテストしていて,
これも便利だと思っていたけど,コメントが多くなってしまいがち

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')
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?