我是unittest
的新手,所以我不确定为什么会收到此错误:
Traceback (most recent call last):
File "filemerge_test.py", line 98, in <module>
main(sys.argv)
File "filemerge_test.py", line 92, in main
filemerge_test.test_runner()
File "filemerge_test.py", line 19, in test_runner
self.addTest(TestFunctionality(self.log, self.options))
File "/nfsdata/DSCluster/home/bli1/filemerge/tests/testcases.py", line 45, in __init__
super(TestFunctionality, self).__init__()
File "/usr/local/lib/python2.7/unittest/case.py", line 191, in __init__
(self.__class__, methodName))
ValueError: no such test method in <class 'testcases.TestFunctionality'>: runTest
完整代码在此处:http://dpaste.com/0W1GEW6
我认为这是因为我没有正确运行测试。
以下是我目前编写测试的摘要:
from testcases import TestFunctionality
class FileMergerTest(unittest.TestSuite)
def __init__(self, log, options):
super(FileMergerTest, self).__init__()
self.options = options
self.log = log
def test_runner(self):
self.addTest(TestFunctionality(self.log, self.options))
self.run()
def main()
...
...
filemerge_test = FileMergerTest(log, options)
filemerge_test.test_runner()
if __name__ == "__main__":
main(sys.argv)
在我导入testcases.py
TestFunctionality
中
class TestFunctionality(unittest.TestCase):
def __init__(self, log, options):
super(TestFunctionality, self).__init__()
self.options = options
self.log = log
...
def test_outputs(self, test_type)
...
...
def run(self):
self.test_outputs("-d")
self.test_outputs("-f")
我尝试添加
if __name__ == '__main__':
unittest.main()
在testcases.py
文件的末尾,但我收到了同样的错误
答案 0 :(得分:3)
我想你想要override runTest
而不是run
:
# def run(self): # <--- remove
def runTest(self): # <--- use this
self.test_outputs("-d")
self.test_outputs("-f")
正如错误所示。