Last active
March 8, 2018 20:56
-
-
Save anaved/b9df568ed798324649fc2dbca630e6c2 to your computer and use it in GitHub Desktop.
Sample test class creator factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Generating tests on the fly | |
import unittest | |
class CheckIntTest(object): | |
def test_isIntReturned(self): | |
print "Calling test method with 2, 3" | |
print "Test method result %s"%(self.calc(2,3)) | |
self.assertIsInstance(self.calc(2,3),int) | |
def m1(self,a,b): | |
return a+b | |
def m2(self,a,b): | |
return a*b | |
if __name__ == '__main__': | |
globals()['M1Test'] = type('M1Test', (CheckIntTest, unittest.TestCase ), {'calc': m1}) | |
globals()['M2Test'] = type('M2Test', (CheckIntTest, unittest.TestCase), {'calc': m2}) | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment