title: How to unit test nested exception in python?
body: <p>I have the scenario as follows,</p>
  <pre class="lang-py prettyprint-override"><code>class SomeException(Exception):
      pass
  
  class SomeOtherException(Exception):
      pass
  
  def first_fn():
      raise SomeException
  
  def second_fn():
      try:
          first_fn()
      except Exception as e:
          raise SomeOtherException from e
  </code></pre>
  <p>I want to check that, somewhere in the chain whether &quot;SomeException&quot; was raised. I have written the unittest as follows,</p>
  <pre class="lang-py prettyprint-override"><code>import unittest
  
  class MyTestCase(unittest.TestCase):
  
      def test_case(self):
          self.assertRaises(SomeException, second_fn)
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  <p>But the unit test fails. But if I do the following,</p>
  <pre class="lang-py prettyprint-override"><code>class MyTestCase(unittest.TestCase):
  
      def test_case(self):
          self.assertRaises(SomeOtherException, second_fn)
  
  </code></pre>
  <p>then it is passing.</p>
  <p>Is there a way to check whether a particular nested exception was raised in the exception stack trace?</p>