Skip to content

Instantly share code, notes, and snippets.

@anaved
Last active March 8, 2018 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anaved/b9df568ed798324649fc2dbca630e6c2 to your computer and use it in GitHub Desktop.
Save anaved/b9df568ed798324649fc2dbca630e6c2 to your computer and use it in GitHub Desktop.
Sample test class creator factory
#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