<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 <<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>> 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'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'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 "test_runner.py", line 98, in <module></div><div> sys.exit(main())</div><div> File "test_runner.py", line 90, in main</div><div> result = runner.run(test_suite)</div><div> File "/usr/lib/python3.6/unittest/runner.py", line 176, in run</div><div> test(result)</div><div> File "/usr/lib/python3.6/unittest/suite.py", line 84, in __call__</div><div> return self.run(*args, **kwds)</div><div> File "/usr/lib/python3.6/unittest/suite.py", line 122, in run</div><div> test(result)</div><div> File "/usr/lib/python3.6/unittest/case.py", line 653, in __call__</div><div> return self.run(*args, **kwds)</div><div> File "/usr/lib/python3.6/unittest/case.py", line 580, in run</div><div> testMethod = getattr(self, self._testMethodName)</div><div>AttributeError: 'TestDisposableLocks' object has no attribute 'runTest'</div></div><div><br></div><div>I've been pulling my hair out trying to figure out why unittest is preferring runTest over test*. Isn'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'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 "important" tests in a runTest method lest they be ignored.</div><div><br></div><div>Also, I'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 "runTest" is "the test", so if it errors out anywhere, that's it for "that test". If pytest can help with that, that'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>