基本的な質問は申し訳ありません。 unittestメソッドを使用して、1つのスクリプトでモデルをチェックしました。今、私の質問は、私は別のファイルからこのスクリプトを呼び出すとテスト結果を保存する方法です。以下は、私のコードのサンプルです:別のスクリプトからpython unittestを呼び出し、すべてのエラーメッセージをエクスポートしてください
**model_test.py**
import unittest
import model_eq #script has models
class modelOutputTest(unittest.TestCase):
def setUp(self):
#####Pre-defined inputs########
self.dsed_in=[1,2]
#####Pre-defined outputs########
self.msed_out=[6,24]
#####TestCase run variables########
self.tot_iter=len(self.a_in)
def testMsed(self):
for i in range(self.tot_iter):
fun = model_eq.msed(self.dsed_in[i],self.a_in[i],self.pb_in[i])
value = self.msed_out[i]
testFailureMessage = "Test of function name: %s iteration: %i expected: %i != calculated: %i" % ("msed",i,value,fun)
self.assertEqual(round(fun,3),round(self.msed_out[i],3),testFailureMessage)
if __name__ == '__main__':
unittest.main()
私が欲しいの次のステップは、ユニット・テスト・スクリプトを実行しますtest_page.pyと呼ばれる別のスクリプトを作成し、変数に結果を保存することです(私はウェブページに結果を投稿する必要があります) 。
test_page.py
from model_test.py import *
a=modelOutputTest.testMsed()
ただし、次のエラーが発生しました。
Traceback (most recent call last):
File "D:\Dropbox\AppPest\rice\Rice_unittest.py", line 16, in <module>
a= RiceOutputTest.testMsed()
TypeError: unbound method testMsed() must be called with RiceOutputTest instance as first argument (got nothing instead)
誰でも私にいくつかの提案を教えてもらえますか?ありがとう!
Nixのおかげでよろしく!私の次の質問は、ループ内で2つのケースを使って関数をテストする必要があることです。投稿されたのはhereです。
あなたは新しい質問にあなたの編集を分割する必要があります。 – Nix
forループに 'return a'があるのはなぜですか?削除する必要があります。 – Nix
ここで新しい質問を移動しました。 http://stackoverflow.com/questions/14285010/python-unit-testing-a-loop-function –