def test_smth(self):
"""
TEST
"""
self.description = 'TEST!'
print(self.shortDescription())
プリントアウトPythonでNone
ドキュメンテーション文字列を持っています
""" <--- this is the first line
TEST
"""
最初の空白行を削除すると、必要なものが表示されます。
"""TEST
"""
➜ /tmp cat t.py
import unittest
class UT(unittest.TestCase):
def test_smth(self):
"""TEST"""
print('shortDescription():', self.shortDescription())
unittest.main()
➜ /tmp python3.6 t.py
shortDescription(): TEST
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
あなたは-v
コマンドラインオプションを使用してテストを実行する場合は、説明がテストメソッド名の代わりに印刷され見ることができます:
➜ /tmp python3.6 t.py -v
test_smth (__main__.UT)
TEST ... shortDescription(): TEST
ok
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
docstringの最初の行に 'TEST'行を入れてみましょう:' '" "" TEST他のもの "" "... –
Bakuriu
また、' test_smth() 'はあなたのクラスのメソッドですか? 'self'パラメータはどこにありますか? – nickie
Betchaこれはあなたがこれらのことをした後に動作します。 – denvaar