title: Running subset of auto-discovered python unittests
body: <p><strong>Short Question</strong><br>
  Is it possible to select, at run time, what unittests are going to be run when using an auto-discovery method in Python's unittest module.  </p>
  
  <p><strong>Background</strong><br>
  I am using the unittest module to run system tests on an external system.  See below for an example sudo-testcase.  The unittest module allows me to create an arbitrary number testcases that I can run using the unittest's testrunner.  I have been using this method roughly 6 months of constant use and it is working out <em>very</em> well.   </p>
  
  <p>At this point in time I am wanting to try and make this more generic and user friendly.  For all of my test suites that I am running now, I have hard coded which tests must run for every system.  This is fine for an untested system, but when a test fails incorrectly (a user connects to the wrong test point etc...)  they must re-run the entire test suite.  As some of the complete suites can take up to 20 min, this is no where near ideal.  </p>
  
  <p>I know it is possible to create <em>custom</em> testsuite builders that could define which tests to run.  My issue with this is that there are hundreds of testcases that can be run and maintaining this would be come a nightmare if test case names change etc...  </p>
  
  <p>My hope was to use <a href="http://readthedocs.org/docs/nose/en/latest/" rel="nofollow">nose</a>, or the built-in <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module to achieve this.  The discovery part seems to be pretty straight forward for both options, but my issue is that only way to select a subset of testcases to run is to define a pattern that exists in the testcase name.  This means I would still have to hard code a list of patterns to define what testcases to run.  So if I have to hard code this list, what is the point of using the auto-discovery (please note this is rhetorical question)? </p>
  
  <p>My end goal is to have a generic way to select which unittests to run during execution, in the form of check boxes or a text field the user can edit.  Ideally the solution would be using Python 2.7 and need would need to run on Windows, OSX, and Linux.  </p>
  
  <p><strong>Edit</strong><br>
  To help clarify, I do not want the tool to generate the list of choices or the check boxes.  The tool ideally would return a list of all of the tests in a directory, including the full path and what Suite (if any) the testcase belongs down.  With this list, I would build the check boxes or a combo box the user interacts with and pass these tests into a testsuite on the fly to run.</p>
  
  <p><strong>Example Testcase</strong> </p>
  
  <pre><code>test_measure_5v_reference 
      1) Connect to DC power supply via GPIB
      2) Set DC voltage to 12.0 V
      3) Connect to a Digital Multimeter via GPIB
      4) Measure / Record the voltage at a given 5V reference test point
      5) Use unittest's assert functions to make sure the value is within tolerance
  </code></pre>