2012-03-03 20 views
1

我有一個包含文檔測試的python腳本的文件夾,我想對其進行單元測試。當我試着使用一個文件中像這樣來測試它:Unittest和doctest,如何使我的文件可調用?

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

我得到這個錯誤:

TypeError: the test to add must be callable 

然而,當我從命令行

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

它的工作原理做。

如何讓我的文件可調用?

回答

2

addTest需要TestCaseTestSuite - 並且您正在傳遞一個字符串。

看一看該文檔在這裏:

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

目前尚不清楚你想要做什麼 - 但如果baseFunctions.py定義的TestCase一個子類,你可以試試這個:

import unittest 
from baseFunctions import MyTestCase 

suite = unittest.TestSuite() 
suite.addTest(MyTestCase) 
unittest.TextTestRunner().run(suite) 
相關問題