title: Custom error messages in Python
body: <p>So I'm practicing some unit test and I have a question about error messages. I'm trying to create a custom error message that will display when the test fails. Here is a basic Hello World program. The test runs fine and everything, but here is the error message I get.</p>
  
  <pre><code>F ====================================================================== FAIL: test_StringContains
   (__main__.TestSuite) ----------------------------------------------------------------------   
  Traceback    (most recent call last): File "Testsuite.py", line 8, in test_StringContains 
  self.assertEqual("Hello,    World", hello_world,"This is a custom error") AssertionError: 'Hello,   
  World' != 'Hello World' - Hello,    World ? - + Hello World : This is a custom error ---------------  
  ------------------------------------------------------- 
  Ran 1 test in 0.000s FAILED (failures=1)
  </code></pre>
  
  <p>So this is expected. Here is my test suite</p>
  
  <pre><code>from  HelloWorld import*
  import unittest
  
  class TestSuite(unittest.TestCase):
  
      def test_StringContains(self):
              self.assertEqual("Hello World", hello_world,"This is a custom")
  
  
  if __name__ == "__main__":
      unittest.main()
  </code></pre>
  
  <p>and here is my run code </p>
  
  <pre><code>hello_world = "Hello World"
  print (hello_world)
  </code></pre>
  
  <p>Super basic, just want to understand how to throw a custom error message. The only thing I want to see if the test fails is <code>This is a custom error</code>, I tried following the Python documentation on Errors &amp; Exceptions here <a href="https://docs.python.org/2/tutorial/errors.html" rel="nofollow">https://docs.python.org/2/tutorial/errors.html</a> , but not sure how to implement it. </p>
  
  <p>I don't know if this is doable or not. Any help is greatly appreciated. Thank you</p>