title: What is the correct way to report an error in a Python unittest in the setUp method?
body: <p>I've read some conflicting advice on the use of <code>assert</code> in the <code>setUp</code> method of a Python unit test. I can't see the harm in failing a test if a precondition that test relies on fails. </p>
  
  <p>For example:</p>
  
  <pre><code>import unittest
  
  class MyProcessor():
      """
      This is the class under test
      """
  
      def __init__(self):
          pass
  
      def ProcessData(self, content):
          return ['some','processed','data','from','content'] # Imagine this could actually pass
  
  class Test_test2(unittest.TestCase):
  
      def LoadContentFromTestFile(self):
          return None # Imagine this is actually doing something that could pass.
  
      def setUp(self):
          self.content = self.LoadContentFromTestFile()
          self.assertIsNotNone(self.content, "Failed to load test data")
          self.processor = MyProcessor()
  
      def test_ProcessData(self):
          results = self.processor.ProcessData(self.content)
          self.assertGreater(results, 0, "No results returned")
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>This seems like a reasonable thing to do to me i.e. make sure the test is able to run. When this fails because of the setup condition we get:</p>
  
  <pre><code>F
  ======================================================================
  FAIL: test_ProcessData (__main__.Test_test2)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "C:\Projects\Experiments\test2.py", line 21, in setUp
      self.assertIsNotNone(self.content, "Failed to load test data")
  AssertionError: unexpectedly None : Failed to load test data
  
  ----------------------------------------------------------------------
  Ran 1 test in 0.000s
  
  FAILED (failures=1)
  </code></pre>