我正在使用unittest.TestSuite()
运行来自类TestNothing
的所有测试。在
我的__init__.py
是:
import unittest
from .test_nothing import TestNothing
def suite():
"""
Define suite
"""
test_suite = unittest.TestSuite()
test_suite.addTests([
unittest.TestLoader().loadTestsFromTestCase(TestNothing),
])
return test_suite
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())
我的test_nothing.py
是:
运行python test_nothong.py
时出现以下错误:
Traceback (most recent call last):
File "test_nothing.py", line 19, in <module>
unittest.TextTestRunner(verbosity=2).run(suite())
File "test_nothing.py", line 13, in suite
unittest.TestLoader().loadTestsFromTestCase(TestNothing)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 56, in loadTestsFromTestCase
loaded_suite = self.suiteClass(map(testCaseClass, testCaseNames))
TypeError: this constructor takes no arguments
事实上,构造函数不需要任何参数。 我建议您让您的测试类TestNothing继承自unittest.TestCase. 像这样,类的构造函数将从构造函数继承unittest.TestCase这需要争论。在
您还可以通过以下链接继续操作python unittest 25.3.1
相关问题 更多 >
编程相关推荐