title: How to test custom exception, message with Python Nose
body: <p><strong>My custom exception classes:</strong></p>
  
  <pre><code>class MyCustomException(Exception):
      pass
  
  class MyCustomRestException(MyCustomException):
  
      def __init__(self, status, uri, msg=""):
          self.uri = uri
          self.status = status
          self.msg = msg
          super(MyCustomException, self).__init__(msg)
  
      def __str__(self):
          return "HTTP ERROR %s: %s \n %s" % (self.status, self.msg, self.uri)
  </code></pre>
  
  <p><strong>My Test</strong></p>
  
  <pre><code># note: @raises(MyCustomRestException) works by itself
  @raises(MyCustomRestException, 'HTTP ERROR 403: Invalid User')
  def test_bad_token():
      sc = SomeClass('xxx', account_number)
      result = ec.method_that_generates_exception()
  </code></pre>
  
  <p><strong>Here's what nose spits back out</strong></p>
  
  <pre><code>12:52:13 ~/sandbox/ec$ nosetests -v
  Failure: AttributeError ('str' object has no attribute '__name__') ... ERROR
  
  ======================================================================
  ERROR: Failure: AttributeError ('str' object has no attribute '__name__')
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/nose/loader.py", line 390, in loadTestsFromName
      addr.filename, addr.module)
    File "/usr/local/lib/python2.7/site-packages/nose/importer.py", line 39, in importFromPath
      return self.importFromDir(dir_path, fqname)
    File "/usr/local/lib/python2.7/site-packages/nose/importer.py", line 86, in importFromDir
      mod = load_module(part_fqname, fh, filename, desc)
    File "/ec/tests/my_client_tests.py", line 16, in &lt;module&gt;
      @raises(MyCustomRestException, 'HTTP ERROR 403: Invalid User')
    File "/usr/local/lib/python2.7/site-packages/nose/tools/nontrivial.py", line 55, in raises
      valid = ' or '.join([e.__name__ for e in exceptions])
  AttributeError: 'str' object has no attribute '__name__'
  
  ----------------------------------------------------------------------
  Ran 1 test in 0.012s
  
  FAILED (errors=1)
  </code></pre>
  
  <p><strong>So ...</strong></p>
  
  <p>My questions is two fold:</p>
  
  <ul>
  <li>How do I fix this error?</li>
  <li>How can I test (individually or altogether):
  <ul>
  <li>Exception Type </li>
  <li>Exception.status </li>
  <li>Exception.uri</li>
  <li>Exception.msg</li>
  </ul></li>
  </ul>
  
  <p><strong>Solution: with help from alynna (below)</strong></p>
  
  <p>This works great.</p>
  
  <pre><code>def test_bad_token():
      sc = SomeClass('xxx', account_number)
  
      with assert_raises(MyCustomRestException) as e:
          sc.method_that_generates_exception()
  
      assert_equal(e.exception.status, 403)
      assert_equal(e.exception.msg, 'Invalid User')
  </code></pre>