<div><div dir="auto">Why does each of your classes have a runTest method in the first place? What is its purpose —- what does it do?</div></div><div dir="auto"><br></div><div dir="auto">—Chris</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 27, 2019 at 12:51 PM Dan Stromberg &lt;<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><br><div><div>Hi folks.</div><div><br></div><div>I&#39;m working on a large Python 3/Python 2 codebase that has several automated test cases and test classes.  I know Python 2 is going away soon.</div><div><br></div><div>We have lots of test* methods in classes that inherit from unittest.TestCase. Each of those classes also provides a runTest method.</div><div><br></div><div>It&#39;s bugging me that the runTest method is getting used, and the test* methods are getting ignored, unless we call the test* methods from the runTest method.</div><div><br></div><div>In fact, if I rename the runTest method from a test class to something unused, I get a traceback:</div><div><div>runTest (tests.test_disposable_locks.TestDisposableLocks)</div><div>No test ... Traceback (most recent call last):</div><div>  File &quot;test_runner.py&quot;, line 98, in &lt;module&gt;</div><div>    sys.exit(main())</div><div>  File &quot;test_runner.py&quot;, line 90, in main</div><div>    result = runner.run(test_suite)</div><div>  File &quot;/usr/lib/python3.6/unittest/runner.py&quot;, line 176, in run</div><div>    test(result)</div><div>  File &quot;/usr/lib/python3.6/unittest/suite.py&quot;, line 84, in __call__</div><div>    return self.run(*args, **kwds)</div><div>  File &quot;/usr/lib/python3.6/unittest/suite.py&quot;, line 122, in run</div><div>    test(result)</div><div>  File &quot;/usr/lib/python3.6/unittest/case.py&quot;, line 653, in __call__</div><div>    return self.run(*args, **kwds)</div><div>  File &quot;/usr/lib/python3.6/unittest/case.py&quot;, line 580, in run</div><div>    testMethod = getattr(self, self._testMethodName)</div><div>AttributeError: &#39;TestDisposableLocks&#39; object has no attribute &#39;runTest&#39;</div></div><div><br></div><div>I&#39;ve been pulling my hair out trying to figure out why unittest is preferring runTest over test*.  Isn&#39;t unittest supposed to fall back on runTest only if there are no test* methods?</div><div><br></div><div>Or do I need something like:</div><div>suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase)</div><div>(from <a href="https://docs.python.org/2/library/unittest.html" target="_blank">https://docs.python.org/2/library/unittest.html</a>)</div><div>?  I tried getting this going with pytest a while back, but eventually set the project aside a while - maybe that was where I got the idea that runTest should be ignored if test* methods are present....</div><div><br></div><div>I still hope to use pytest with this code at some point, but for now I&#39;d be happy if the unittest test discovery just worked the way I expect.  My main goals for switching to pytest is to parallelise the tests, and to stop having to list &quot;important&quot; tests in a runTest method lest they be ignored.</div><div><br></div><div>Also, I&#39;m finding that sometimes raising an exception terminates the testing for the entire suite, rather than leading to a failed/errored test and continuing, presumably because &quot;runTest&quot; is &quot;the test&quot;, so if it errors out anywhere, that&#39;s it for &quot;that test&quot;.  If pytest can help with that, that&#39;d be awesome.</div><div><br></div><div>What can I do to get runTest out of the mix when test* methods are present?</div><div><br></div><div>Thanks!</div><div><br></div><div class="m_6744481978676687114gmail-yj6qo"></div></div></div></div>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" rel="noreferrer" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</blockquote></div></div>