OniOni/python-parallel-wd — pull request #5 by EliAndrewC (2013-07-15 20:45:27+00:00)
Title: TestCase.__init__ never called on SubTest

When I try to run

self.assertEqual(x, y)

in one of my tests, it fails with the error

AttributeError: 'SubTest' object has no attribute '_type_equality_funcs'

This is because we never call TestCase.__init__ in the SubTest.__init__, and according to the docstring, "If it is necessary to override the __init__ method, the base class __init__ method must always be called." (you can see this by running "pydoc unittest.TestCase")

TestCase.__init__ expects to be passed a string which is the name of the method being tested; this will fail if you pass a non-existing method name. Unfortunately, we're manually constructing SubTest and then passing that as the "self" to our real test case method, defined elsewhere, so we can't use that method's name. Fortunately, it's okay if we don't pass the real method name, so long as we pass any method name that is known to exist; I use "__init__" since that will always exist.

This simple change should allow methods such as self.assertEqual to work, which currently raise a confusing error message.