<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><br></div><div>I&#39;m inclined to agree with you - something unusual is happening in the code on my end.</div><div><br></div><div>Sadly, I&#39;m running out of ideas for where to look for the customization, and the person who set it up is most likely no longer with the company.</div><div><br></div><div>Thanks though.</div><div><br></div><div>How about this: If someone were to try to set up such a thing, where tests for a given test class are all ordered based on their appearance in a single runTest method, how would you choose to go about setting that up?</div><br>We have a test_runner.py that controls our overall test execution, but it doesn&#39;t have anything obviously runTest-related.<div><br></div><div>The closest thing that would be relevant in test_runner.py looks like:</div><div><div>    test_suite.addTest(TestDisposableLocks())</div><div><br></div><div>    # test_suite.addTest(TestTicketETL())</div><div><br></div><div>    runner = unittest.TextTestRunner(verbosity=3)</div><div>    result = runner.run(test_suite)</div><div>    if result.errors or result.failures:</div><div>        return 1</div><div>    else:</div><div>        return 0</div><div><br></div><div>I&#39;m kind of wondering if TextTestRunner or runner.run is doing something odd.  I&#39;ve tried stepping into these with pudb, but it quickly turned into a twisty maze.</div><div><br></div><div>Also, I wonder if one of the many pypi packages we&#39;re installing is doing it.  Here are the ones that match the string &#39;test&#39;:<br><div>$ python -m pip freeze | grep -i test</div><div>below cmd output started 2019 Tue Aug 27 04:41:22 PM PDT</div><div>pytest==4.6.3</div><div>pytest-cov==2.5.0</div><div>pytest-forked==1.0.2</div><div>pytest-xdist==1.29.0</div><div>unittest2==0.5.1</div></div><div><br></div><div>Thanks.</div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 27, 2019 at 4:31 PM Chris Jerdonek &lt;<a href="mailto:chris.jerdonek@gmail.com">chris.jerdonek@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">In my experience, I&#39;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 &quot;runTest.&quot; If you look at unittest&#39;s source code, you&#39;ll see that &quot;runTest&quot; is the default test name if no method name is passed to TestCase&#39;s constructor. I&#39;m guessing the behavior you&#39;re experiencing is due to a custom test runner or discovery or some other customization under your control. I&#39;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 &lt;<a href="mailto:drsalists@gmail.com" target="_blank">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"><br><div>It calls each &quot;important&quot; test in turn.  It&#39;s like a poor-person&#39;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 &lt;<a href="mailto:chris.jerdonek@gmail.com" target="_blank">chris.jerdonek@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><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" target="_blank">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"><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="gmail-m_5983439743567984654gmail-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>
</blockquote></div></div></div></div></div>