Python的unittest.TestCase对象没有属性'runTest'
Python的unittest.TestCase对象没有属性'runTest'
对于以下代码:
import unittest class Test(unittest.TestCase): def test1(self): assert(True == True) if __name__ == "__main__": suite = unittest.TestSuite() suite.addTest(Test()) unittest.TextTestRunner().run(suite)
使用Python 3来执行,会引发以下错误:
Traceback (most recent call last): File "test.py", line 10, inunittest.TextTestRunner().run(suite) File "/usr/lib/python3.2/unittest/runner.py", line 168, in run test(result) File "/usr/lib/python3.2/unittest/suite.py", line 67, in __call__ return self.run(*args, **kwds) File "/usr/lib/python3.2/unittest/suite.py", line 105, in run test(result) File "/usr/lib/python3.2/unittest/case.py", line 477, in __call__ return self.run(*args, **kwds) File "/usr/lib/python3.2/unittest/case.py", line 408, in run testMethod = getattr(self, self._testMethodName) AttributeError: 'Test' object has no attribute 'runTest'
但是unittest.main()
可以正常工作。