Reputation: 483
Running first_TestCase
and second_TestCase
separately all works fine.
But when i created TestSuite, it runs only first_TestCase
. Why is this happening?
import unittest
from first_TestCase import first_TestCase
from second_TestCase import second_TestCase
def suite():
suite = unittest.TestSuite()
suite.addTest(first_TestCase())
suite.addTest(second_TestCase())
return suite
if __name__ == "__main__":
suite = unittest.defaultTestLoader.loadTestsFromTestCase(first_TestCase)
unittest.TextTestRunner().run(suite)
Upvotes: 1
Views: 688
Reputation: 3146
You're saying:
if __name__ == "__main__":
suite = unittest.defaultTestLoader.loadTestsFromTestCase(first_TestCase)
unittest.TextTestRunner().run(suite)
You're loading tests from only first_TestCase
right before you run via the TextTestRunner
. You're never hitting that suite() function.
You should do:
if __name__ == "__main__":
unittest.TextTestRunner().run(suite())
Because you're not calling the suite() function in your current implementation.
Upvotes: 1
Reputation: 483
Instead of:
if __name__ == "__main__":
suite = unittest.defaultTestLoader.loadTestsFromTestCase(first_TestCase)
unittest.TextTestRunner().run(suite)
I should use:
if __name__ == "__main__":
unittest.main()
Upvotes: 0