title: Caching result of setUp() using Python unittest
body: <p>I currently have a unittest.TestCase that looks like..</p>
  
  <pre><code>class test_appletrailer(unittest.TestCase):
      def setup(self):
          self.all_trailers = Trailers(res = "720", verbose = True)
  
      def test_has_trailers(self):
          self.failUnless(len(self.all_trailers) &gt; 1)
  
      # ..more tests..
  </code></pre>
  
  <p>This works fine, but the <code>Trailers()</code> call takes about 2 seconds to run.. Given that <code>setUp()</code> is called before each test is run, the tests now take almost 10 seconds to run (with only 3 test functions)</p>
  
  <p>What is the correct way of caching the <code>self.all_trailers</code> variable between tests?</p>
  
  <p>Removing the setUp function, and doing..</p>
  
  <pre><code>class test_appletrailer(unittest.TestCase):
      all_trailers = Trailers(res = "720", verbose = True)
  </code></pre>
  
  <p>..works, but then it claims "Ran 3 tests in 0.000s" which is incorrect.. The only other way I could think of is to have a cache_trailers global variable (which works correctly, but is rather horrible):</p>
  
  <pre><code>cache_trailers = None
  class test_appletrailer(unittest.TestCase):
      def setUp(self):
          global cache_trailers
          if cache_trailers is None:
              cache_trailers = self.all_trailers = all_trailers = Trailers(res = "720", verbose = True)
          else:
              self.all_trailers = cache_trailers
  </code></pre>