Hello, everyone.
I would like a seperate class to run all of my tests, and then call that class from main to display the results. Unfortunately, I am getting an error like this:
Traceback (most recent call last):
File "/home/dhatt/workspace/pyqt_DALA_ServiceTracker/src/Main.py", line 21, in <module>
allsuite = unittest.TestLoader.loadTestsFromModule(TestAllSuite)
TypeError: unbound method loadTestsFromModule() must be called with TestLoader instance as first argument (got type instance instead)
How do I change my code so that I can run my tests?
I am using python 2.6.5.
If you find that my testing structure itself also poses a problem (where main calls the main testing class that then calls all my other testing classes), let me know. I am open to suggestions to a better layout of my testing code (the examples off of the internet only give you the very basics when using unittest)
Here is my code from TestAllClass (it is calling other test classes)
import unittest
from TestSettings import TestSettings
from TestConnectDB import TestConnectDB
class TestAllSuite(unittest.TestCase):
def testsuite(self):
suite_settings = TestSettings.suite()
suite_connectDB = TestConnectDB.suite()
alltests = unittest.TestSuite([suite_settings, suite_connectDB])
return alltests
and here is part of my main that calls TestAllClass
if __name__ == '__main__':
allsuite = unittest.TestLoader.loadTestsFromModule(TestAllSuite)
unittest.TextTestRunner(verbosity=2).run(allsuite)
Here is an example of one of my test classes (if that helps):
from Settings import Settings
import unittest
class TestSettings(unittest.TestCase):
def suite(self):
suite = unittest.TestSuite()
tests = ['test_confirm_ip', 'test_valid_conn','test_correct_location']
return unittest.TestSuite(map(suite, tests))
def setUp(self):
self._test_settings = Settings('/home/dhatt/ServiceTrackerSettings.ini')
self.ip_add, self.conn, self.digby = self._test_settings._get_config_variables()
def tearDown(self):
self._test_settings = None
self.ip_add = None
self.conn = None
self.digby = None
def test_confirm_ip(self):
self.assertEqual((str(self.ip_add)), ('142.176.195.250'))
def test _confirm_conn(self):
self.assertEqual((str(self.conn)), ('conn1'))
def test_confirm_location(self):
self.assertEqual((self.digby), (True))