<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 3, 2019 at 2:05 PM Dan Stromberg &lt;<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div>Hi folks.</div><div><br></div><div>I&#39;m still working on converting that large codebase from unittest to pytest (in parallel with a couple of other projects).</div><div><br></div><div>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:</div><div><div>      runner = unittest.TextTestRunner(verbosity=3)                                                                         </div><div>      result = runner.run(test_suite)                                                                                                  </div></div><div><br></div><div>Now I have a new question: Does pytest allow one test class to inherit from another?</div><div><br></div><div>I&#39;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.</div><div><br></div><div>Specifically, we have lots of things like:</div><div><div>      def setup_method(self):                                                                                                          </div><div>          super(TestFeatures, self).setup_method()                                                                                     </div></div><div>And we -had- a lot of:</div><div>      def __init__(self):</div><div>          super(TestFeatures, self).__init__()</div><div>...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.</div><div><br></div><div>However, now from our many setup_method&#39;s I&#39;m getting things like:</div><div><div>&gt;       super(FeatureElasticSearchAwareTestCase, self).setup_method()</div><div>E       AttributeError: &#39;super&#39; object has no attribute &#39;setup_method&#39;</div></div><div><br></div><div>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&#39;s why it cares about object.</div><div><br></div><div>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&#39;m working on?</div><div><br></div><div>Thanks!</div></div></div></div></div></blockquote><div><br></div><div>Based on this test code, inheritance works, at least sometimes:</div><div><br></div><div>#!/usr/bin/env python3.7</div><div><br></div><div>&quot;&quot;&quot;A quick test to see if pytest can deal with an exceptionally simple inheritance hierarchy.&quot;&quot;&quot;</div><div><br></div><div><br></div><div>class TestClass1(object):</div><div>    &quot;&quot;&quot;Test 1.&quot;&quot;&quot;</div><div>    def setup_method(self):</div><div>        print(&quot;In TestClass1&#39;s setup_method()&quot;)</div><div><br></div><div>    def teardown_method(self):</div><div>        print(&quot;In TestClass1&#39;s teardown_method()&quot;)</div><div><br></div><div>    def test_1(self):</div><div>        print(&#39;In test1&#39;)</div><div>        raise ValueError</div><div><br></div><div><br></div><div>class TestClass2(TestClass1):</div><div>    &quot;&quot;&quot;Test 2.&quot;&quot;&quot;</div><div>    def setup_method(self):</div><div>        print(&quot;In TestClass2&#39;s setup_method()&quot;)</div><div>        super(TestClass2, self).setup_method()</div><div><br></div><div>    def teardown_method(self):</div><div>        print(&quot;In TestClass2&#39;s teardown_method()&quot;)</div><div>        super(TestClass2, self).teardown_method()</div><div><br></div><div>    def test_2(self):</div><div>        print(&#39;In test2&#39;)</div><div>        raise ValueError</div><div><br></div><div><br></div><div>So now I&#39;m left wondering: Why doesn&#39;t it work in my large project?</div><div><br></div></div></div></div></div></div>