Skip to content

Instantly share code, notes, and snippets.

@brent-hoover
Created January 20, 2014 14:56
Show Gist options
  • Select an option

  • Save brent-hoover/8521235 to your computer and use it in GitHub Desktop.

Select an option

Save brent-hoover/8521235 to your computer and use it in GitHub Desktop.
Parameterizing Unit Tests
import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequense(unittest.TestCase):
pass
def test_generator(a, b):
def test(self):
self.assertEqual(a,b)
return test
if __name__ == '__main__':
for t in l:
test_name = 'test_%s' % t[0]
test = test_generator(t[1], t[2])
setattr(TestSequense, test_name, test)
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment