title: Python unit test coverage for multiple modules
body: <p>I searched for a long time and surprisingly found no satisfactory answer.</p>
  
  <p>I have multiple modules/files in my Python project that I wrote unit tests for using <code>unittest</code>. The structure is such that I have production-modules <code>module_A.py</code> and <code>module_B.py</code> in one directory (say <code>myproject/production</code>) and corresponding test-files <code>test_module_A.py</code> and <code>test_module_B.py</code> in a sibling directory (say <code>myproject/tests</code>).</p>
  
  <p>Now I have <code>coverage.py</code> installed and want to run all the tests associated with the project (i.e. all <code>.py</code>-files with the prefix <code>test_</code> from the <code>tests</code> directory) and receive a coverage report showing the coverage for all the production-modules (<code>module_A.py</code> and <code>module_B.py</code>).</p>
  
  <p>I figured out that I can do this by running the following commands from the <code>myproject/tests</code> directory:</p>
  
  <ul>
  <li><code>coverage erase</code></li>
  <li><code>coverage run -a --source myproject.production test_module_A.py</code></li>
  <li><code>coverage run -a --source myproject.production test_module_B.py</code></li>
  <li><code>coverage report</code></li>
  </ul>
  
  <p>This gives me that nice table with all my production modules listed and their coverage results. So far so good.</p>
  
  <p><strong>But can I do this with just one command?</strong> Assuming I have not 2 but 20 or 200 tests that I want to include in one report, doing this "by hand" seems ridiculous.</p>
  
  <p>There must be a way to automate this, but I can't seem to find it. Sure a shell-script might do it, but that is rather clumsy. I am thinking of something akin to <code>unittest discover</code>, but for <code>coverage.py</code> this doesn't seem to work.</p>
  
  <p>Or could I accomplish this using the coverage-API somehow? So far I had no luck trying.</p>
  
  <p>.</p>
  
  <p><strong>SOLUTION:</strong> (credit to Mr. Ned Batchelder)</p>
  
  <p>From <code>myproject/tests</code> directory run:</p>
  
  <p><code>coverage run --source myproject.production -m unittest discover &amp;&amp; coverage report</code></p>
  
  <p>One line, doing exactly what was needed.</p>