OniOni / python-parallel-wd

Run selenium tests in multiple browsers with minimum hastle. Python flavor !
34 stars 13 forks source link

TestCase.__init__ never called on SubTest #5

Open EliAndrewC opened 11 years ago

EliAndrewC commented 11 years ago

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.

Themanwithoutaplan commented 11 years ago

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 commented 10 years ago

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 commented 10 years ago

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