Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Unittest2 - avoid including a TestCase in discover()
    text
    copied!<p>I'm using <code>unittest2</code> on <code>Python2.5</code> to discover tests with <code>unittest.TestLoader.discover</code>, like this:</p> <pre><code>suite = unittest2.loader.TestLoader().discover(test_path) unittest2.TextTestRunner(verbosity=2, resultclass=ColorTestResult).run(suite) </code></pre> <p>for some <code>test_path</code> at the base of my project.</p> <p>I've a base class that's extended and overloaded by numerous others, but I'd like to test that those derivatives do not have regressions. Let's call that base class <code>A</code> and its derivates <code>A1</code>, <code>A2</code>, etc.</p> <p>I'd like to create a <code>unittest2.TestCase</code> base class that can be overloaded for each of the derivatives of <code>A</code>. In other words, I'd like to have a hierarchy something like this:</p> <pre><code>class A: pass class A1(A): pass class UT(unittest2.TestCase): target = A class UT2(UT): target = A1 </code></pre> <p>Now the trick is that I'm making <code>A</code> into an abstract class, and <code>UT</code> will fail on virtually all of the test cases that would appropriately pass for <code>UT2</code>, etc.</p> <p>The simplest solution to me seems to be to have unittest2's <code>discover</code> somehow "skip" <code>UT</code>. I would think this would be possible by putting it into a file other than one matching patter 'test*.py', though this seems not to be the case.</p> <p>Are there any solutions to the above scenario that might be appropriate?</p> <p>I'd be grateful for any thoughts and suggestions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload