doctest
doctestのメモ
-
付与されたタグ:
- Python
def hello(s):
"""return hello
>>> hello("World")
'Hello World'
>>> hello("Python")
'Hello Python!!'
>>> hello("Perl")
'Hello Perl'
>>> hello("Ruby")
'Hello Ruby'
"""
if s == 'Python':
"Hello " + s + "!!"
else:
return "Hello " + s
def _test():
import doctest
doctest.testmod()
if __name__ == '__main__':
_test()
を実行すると次にような結果になる。
**********************************************************************
File "doctest_sample.py", line 6, in __main__.hello
Failed example:
hello("Python")
Expected:
'Hello Python!!'
Got nothing
**********************************************************************
1 items had failures:
1 of 4 in __main__.hello
***Test Failed*** 1 failures.
return で値を返すのを忘れているのだから当然失敗する。という話でした。お手軽テストにはなるのか。