Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The default <code>unittest.main()</code> uses the default test loader to make a TestSuite out of the module in which main is running.</p> <p>You don't have to use this default behavior.</p> <p>You can, for example, make three <a href="http://docs.python.org/library/unittest.html#unittest.TestSuite" rel="noreferrer">unittest.TestSuite</a> instances.</p> <ol> <li><p>The "fast" subset.</p> <pre><code>fast = TestSuite() fast.addTests( TestFastThis ) fast.addTests( TestFastThat ) </code></pre></li> <li><p>The "slow" subset.</p> <pre><code>slow = TestSuite() slow.addTests( TestSlowAnother ) slow.addTests( TestSlowSomeMore ) </code></pre></li> <li><p>The "whole" set.</p> <pre><code>alltests = unittest.TestSuite([fast, slow]) </code></pre></li> </ol> <p>Note that I've adjusted the TestCase names to indicate Fast vs. Slow. You can subclass unittest.TestLoader to parse the names of classes and create multiple loaders.</p> <p>Then your main program can parse command-line arguments with <a href="http://docs.python.org/library/optparse.html" rel="noreferrer">optparse</a> or <a href="https://docs.python.org/dev/library/argparse.html" rel="noreferrer">argparse</a> (available since 2.7 or 3.2) to pick which suite you want to run, fast, slow or all.</p> <p>Or, you can trust that <code>sys.argv[1]</code> is one of three values and use something as simple as this</p> <pre><code>if __name__ == "__main__": suite = eval(sys.argv[1]) # Be careful with this line! unittest.TextTestRunner().run(suite) </code></pre>
 

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