TestCase.__init__ never called on SubTest #5
+1
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.