Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Created April 24, 2017 22:04
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 juanpabloaj/373fb118c38421013a8a444b1ce85c08 to your computer and use it in GitHub Desktop.
Save juanpabloaj/373fb118c38421013a8a444b1ce85c08 to your computer and use it in GitHub Desktop.
import unittest
class TestData(type):
def __new__(cls, name, bases, attrs):
callables = dict([
(meth_name, meth) for (meth_name, meth) in attrs.items() if
meth_name.startswith('_test')
])
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