[TIP] Inheritance of TestClasses?
Dan Stromberg
drsalists at gmail.com
Tue Sep 3 14:05:07 PDT 2019
Hi folks.
I'm still working on converting that large codebase from unittest to pytest
(in parallel with a couple of other projects).
I was able to get past the runTest issue I was seeing, with the great help
on this list. It turned out to be because we were using unittest.TestCase
and:
runner = unittest.TextTestRunner(verbosity=3)
result = runner.run(test_suite)
Now I have a new question: Does pytest allow one test class to inherit from
another?
I'm asking, because our unittest test cases use inheritance a lot. With
our somewhat strange use of runTest, this was working well enough, but with
pytest it appears to be a problem.
Specifically, we have lots of things like:
def setup_method(self):
super(TestFeatures, self).setup_method()
And we -had- a lot of:
def __init__(self):
super(TestFeatures, self).__init__()
...but I eliminated those by merging them into setup_method(). I did this
because pytest apparently skips any test class that has an __init__ method.
However, now from our many setup_method's I'm getting things like:
> super(FeatureElasticSearchAwareTestCase, self).setup_method()
E AttributeError: 'super' object has no attribute 'setup_method'
And I chased up the inheritance hierarchy, and found that every super class
but object itself has a .setup_method(). This is a 2.x and 3.x codebase,
so that's why it cares about object.
So I ask: does pytest eliminate the possilbity of using an inheritance
hierarchy in the test code? Or is this another oddity of the codebase I'm
working on?
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20190903/98999790/attachment.htm>
More information about the testing-in-python
mailing list