title: setUpModule, tearDownModule and imports can be out of order under nose
body: <p>I have some Python unittests that I am discovering and running with nose. I've observed some strange sequencing of the setUpModule(), tearDownModule() and imports of test modules.  I have this (example) directory structure:</p>
  
  <pre><code>test1.py
  test_dir/test2.py
  </code></pre>
  
  <p>Both test1.py and test2.py look like this:</p>
  
  <pre><code>import sys
  import unittest
  
  def flushwrite(text):
      sys.stdout.write(text + '\n')
      sys.stdout.flush()
  
  flushwrite("import %s" % __name__)
  
  def setUpModule():
      flushwrite("setUp %s" % __name__)
  
  def tearDownModule():
      flushwrite("tearDown %s" % __name__)
  
  class Test(unittest.TestCase):
      def test1(self):
          flushwrite("running %s.test1" % __name__)
  </code></pre>
  
  <p>When I run <code>nosetests -s test1.py test_dir/test2.py</code>, I see this sequence:</p>
  
  <ol>
  <li>import test1</li>
  <li>import test2</li>
  <li>setUp test1</li>
  <li>running test1.test1</li>
  <li>tearDown test1</li>
  <li>setUp test2</li>
  <li>running test2.test1</li>
  <li>tearDown test2</li>
  </ol>
  
  <p>Which is what I'd expect/desire.  When I run <code>nosetests -s test1.py test_dir</code> (using test discovery to find test2.py), I see this sequence:</p>
  
  <ol>
  <li>import test1</li>
  <li>import test2</li>
  <li>setUp test1</li>
  <li>running test1.test1</li>
  <li>setUp test2</li>
  <li>running test2.test1</li>
  <li><strong>tearDown test2</strong></li>
  <li>tearDown test1</li>
  </ol>
  
  <p>Note that tearDown for test1 executes AFTER test2's tests.  This means that the system is not in a clean state when test2 runs!  Obviously, this can be a problem in a production environment of thousands of tests discovered from a large directory tree.</p>
  
  <p>What's up? Am I misunderstanding something? Is there a way to ensure that tearDownModule gets run after each test module?</p>