0
私はDjangoがテストで何らかの出力を出力することは想定していませんでした....私はデータ入力に役立ついくつかのprintステートメントを持っていますが、TestCase
を書いていますが、迷惑な端末に接続します。Djangoは印刷出力をテストするのはなぜですか?
テスト中にdjangoがそれらを印刷するのを止める方法はありますか?なぜこれをやっていないのですか?
モデル方法:
def wiktionary_lookup(self, wiktionary_prefix, driver):
driver.get("http://%s.wiktionary.org/wiki/%s" % (wiktionary_prefix, self.name))
definitions = driver.find_elements_by_xpath("//h3/following-sibling::ol/li")
count = 0
defs_list = []
print "\tWIKTIONARY DEFINITIONS:\n"
for i in definitions:
i = i.text.split('\n')
for j in i:
#Takes out an annoying "[quotations]" in the end of the string, soemtimes.
j = re.sub(u'\u2003\[quotations \u25bc\]', '', j)
print "\t%d. %s" % (count, j)
defs_list.append(j)
count += 1
print "\n"
return defs_list
テスト:
def test_wiktionary_lookup(self):
language = Language.objects.create(name='eng', full_name='English')
word = Word.objects.create(language=language, name='testword')
driver = webdriver.Chrome()
output = word.wiktionary_lookup('en', driver)
self.assertTrue(len(output) == 0)
word = Word.objects.create(language=language, name='table')
output = word.wiktionary_lookup('en', driver)
self.assertTrue(len(output) > 0)
あなたのコードを投稿してください。 –
これは正常です。あなたのコードで 'print'ステートメントを使うべきではありません。あなたが有用な場合は、ロガーを使用することができます。 –
@ZachZundelコードpsoted – deltaskelta