2012-03-03 4 views
1

私は単体テストを行いたいドキュメントテストを含むpythonスクリプトを含むフォルダを持っています。私はこのような一つのファイルでそれをテストしようとすると:私はそれが動作Unittestとdoctest、ファイルを呼び出し可能にする方法は?

python '/homes/ndeklein/workspace/MS/PyMS/pyMS/baseFunctions.py' 

コマンドラインからそれを行う際に、しかし

TypeError: the test to add must be callable 

import unittest 
suite = unittest.TestSuite() 
suite.addTest('/homes/ndeklein/workspace/MS/PyMS/pyMS/baseFunctions.py') 
unittest.TextTestRunner().run(suite) 

私はこのエラーを取得します。

ファイルを呼び出し可能にするにはどうすればよいですか?

答えて

2

addTestは、TestCaseまたはTestSuiteです。文字列を渡しています。

は、ここにドキュメントを見てください:

http://docs.python.org/library/unittest.html

それはあなたがやりたい正確に何明確ではないのです - しかしbaseFunctions.pyTestCaseのサブクラスを定義している場合、あなたはこの試みることができる:

import unittest 
from baseFunctions import MyTestCase 

suite = unittest.TestSuite() 
suite.addTest(MyTestCase) 
unittest.TextTestRunner().run(suite) 
関連する問題