<div dir="ltr">In my experience, I've never needed to add a runTest() method to TestCase classes, and if a TestCase class lacks any test methods, it will simply run no tests -- not try to run "runTest." If you look at unittest's source code, you'll see that "runTest" is the default test name if no method name is passed to TestCase's constructor. I'm guessing the behavior you're experiencing is due to a custom test runner or discovery or some other customization under your control. I've never seen this behavior from out-of-the-box uses of unittest.<div><div><br></div><div>--Chris</div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 27, 2019 at 1:40 PM Dan Stromberg <<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>> 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"><br><div>It calls each "important" test in turn. It's like a poor-person's discovery. If a test is left out of runTest by accident, it gets ignored.</div><div><br></div><div>Like:</div><div> def runTest(self):</div><div> assert self.test_red()</div><div> assert self.test_green()</div><div> assert self.test_blue()</div><div><br></div><div>Or:</div><div> def runTest(self):</div><div> self.test_anomaly_post()</div><div> self.test_feature_get()</div><div> self.test_feature_put()</div><div><br></div><div>Thanks for asking.</div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 27, 2019 at 1:34 PM Chris Jerdonek <<a href="mailto:chris.jerdonek@gmail.com" target="_blank">chris.jerdonek@gmail.com</a>> 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><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" target="_blank">drsalists@gmail.com</a>> 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"><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="gmail-m_-6253198377014986178gmail-m_-3206943857981148148m_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>
</blockquote></div>
</blockquote></div>