title: How sys.exc_info() works?
body: <p>The behavior of sys.exc_info() is described in <a href="http://docs.python.org/2/library/sys.html" rel="nofollow noreferrer">python docs</a> and on <a href="https://stackoverflow.com/questions/1611561/python-error-handling-with-try-finally/1611572">SO</a> and <a href="https://stackoverflow.com/questions/7375492/proper-care-and-safety-when-dealing-with-python-traceback-objects-from-sys-exc-i">SO</a> as:</p>
  
  <ul>
  <li>within an except block or methods called by an except block, a triple describing the exception</li>
  <li>elsewhere, a triple of None values</li>
  </ul>
  
  <p>So why does this nosetest fail?</p>
  
  <pre><code>def test_lang_stack(self):
      try:
          self.assertEquals((None,None,None), sys.exc_info()) # no exception
          a = 5 / 0
      except:
          self.assertNotEquals((None,None,None), sys.exc_info())  # got exception
      else:
          self.fail('should not get here')
      #finally:
      #    self.assertEquals((None,None,None), sys.exc_info()) # already handled, right?
      self.assertEquals((None,None,None), sys.exc_info())  # already handled, right?
  </code></pre>
  
  <p>It fails at the last line. If you uncomment the finally block, it fails there instead.</p>
  
  <p>I do see that if I put all this inside one method and call from a different method, then the calling method does not see the exception.  The exc_info value seems to remain set to the end of the method where an exception is thrown, even after the exception is handled.</p>
  
  <p>I'm using python2.7 on OSX.</p>