Skip to content

Conversation

@EliAndrewC
Copy link

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.

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.
fixed typo from previous commit
@Themanwithoutaplan
Copy link

I can confirm the error when running self.assertEqual(x, y). Two workarounds: use self.assertTrue(x == y) or use a different test runner such as py.test.

@cbier
Copy link

cbier commented Mar 6, 2014

I think this is causing a problem for me, too. I cannot access certain self vars that were defined in my test class.

So it's causing me to encounter errors like this:

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

env_type being a variable that was set in my test class.

@cbier
Copy link

cbier commented Mar 6, 2014

Actually tried putting your code into my local installation, and it doesn't fix the issue I'm encountering. Still investigating why this is happening... Any feedback or ideas would be helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants