Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import unittest
class TestData(type):
def __new__(cls, name, bases, attrs):
callables = dict([
(meth_name, meth) for (meth_name, meth) in attrs.items() if
for meth_name, meth in callables.items():
for i in range(5):
new_meth_name = meth_name[1:]
test_name = '{}_{}'.format(new_meth_name, i)
attrs[test_name] = lambda self: meth(self, i)
return type.__new__(cls, name, bases, attrs)
class Test(unittest.TestCase):
__metaclass__ = TestData
def test_one(self):
assert True
def _test_base(self, data):
assert data != None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.