I've written some tests using unittest as below and I want to reuse them in another class where I'm stuck and need help.. Code snippets are as below.
MyTestClass.pyClass MyTestClass(unittest.TestCase): @classmethoddef test_TC01_set(self):self.devAddr = "127.0.0.0"self.teststoSkip = 'TC02'def skip(type):if type in self.teststoSkip:self.skipTest('skipped!!') #unittest.Testcase methoddef test_TC02(self):self.skip('TC02')print 'test_TC02 will do other tasks'def test_TC03(self):self.skip('TC03')print 'test_TC03 will do other tasks'
This will work fine. Now I want to reuse the same testcases in another class. say,
RegressionMyTest.pyfrom MyTestClass import MyTestClassClass RegressionMyTest(MyTestClass):@classmethoddef setupmytest(self):self.test_TC01_set(self)#this will work fine since it is accessing classmethodself.tes_TC02(self)#cant access like this since it is not a class methodself.tes_TC03(self)#cant access like this since it is not a class method
How can I reuse the tests in MyTestClass in RegressionMyTest so that both MyTestClass and RegressionMyTest should work if they are run individually using nosetests/unittest.