I have django unittests that are pretty much the following format:
class Tests(unittest.TestCase):
def check(self, i, j):
self.assertNotEquals(0, i-j)
for i in xrange(1, 4):
for j in xrange(2, 6):
def ch(i, j):
return lambda self: self.check(i, j)
setattr(Tests, "test_%r_%r" % (i, j), ch(i, j))
A function that returns a lambda that is bound as a method via setattr.
...which is an eyesore and as unreadable as you can get in Python without really trying to obfuscate.
How can I achieve the same functionality in a more readable way, preferably without lambda
.
For reference, see the original SO question about the subject.