Skip to content

Instantly share code, notes, and snippets.

@mbr
Created June 8, 2012 18:13
Show Gist options
  • Save mbr/2897359 to your computer and use it in GitHub Desktop.
Save mbr/2897359 to your computer and use it in GitHub Desktop.
Parametric tests in python
#!/usr/bin/env python
# coding=utf8
# before, in virtualenv:
# pip install testscenarios testtools
# (unfortunately, testscenarios doesn't list testtools as a dependency)
# "real code"
class Backend(object):
pass
class BackendA(Backend):
name = 'backend_a'
class BackendB(Backend):
name = 'backend_b'
class BackendC(Backend):
name = 'backend_c'
# test code
from testscenarios import TestWithScenarios
class BackendsTest(TestWithScenarios):
scenarios = {
'ba': {
'backend_class': BackendA,
'backend_name': 'backend_a'
},
'backend_b': {
'backend_class': BackendB,
'backend_name': 'backend_b',
},
'backend_c': {
'backend_class': BackendC,
'backend_name': 'wrong_name'
}
}.items()
def setUp(self):
self.backend = self.backend_class()
def test_name(self):
self.assertEqual(self.backend_name, self.backend.name)
if '__main__' == __name__:
import unittest
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment