python-parallel-wd icon indicating copy to clipboard operation
python-parallel-wd copied to clipboard

TestCase.__init__ never called on SubTest

Open EliAndrewC opened this issue 11 years ago • 3 comments

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.

EliAndrewC avatar Jul 15 '13 20:07 EliAndrewC

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.

Themanwithoutaplan avatar Oct 03 '13 11:10 Themanwithoutaplan

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 avatar Mar 06 '14 18:03 cbier

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

cbier avatar Mar 06 '14 19:03 cbier