Python unittest.TestCase object has no attribute 'runTest'
You have to specify the test method name (test1
):
import unittest
class Test(unittest.TestCase):
def test1(self):
assert(True == True)
if __name__ == "__main__":
suite = unittest.TestSuite()
suite.addTest(Test('test1')) # <----------------
unittest.TextTestRunner().run(suite)
Or, if you want to run all tests in the file, Just calling unittest.main()
is enough:
if __name__ == "__main__":
unittest.main()
You need to invoke a TestLoader
:
if __name__ == "__main__":
suite = unittest.defaultTestLoader.loadTestsFromTestCase(Test)
unittest.TextTestRunner().run(suite)