title: catch sys.exit with py.test
body: <p>How do I catch <code>sys.exit()</code> with pytest in a function that returns a generator? In the following code, <code>f()</code> only returns <em>hello world</em> if <code>x = True</code>. But using <code>x = False</code>, I expect the code to launch <code>SystemExit</code>. </p>
  
  <pre><code>def test_generator():
      with pytest.raises (SystemExit) as excinfo:
          def f(x = True):
              if x:
                  yield 'hello world'
              sys.exit('Test')
          f (x = False)
      assert 'Test' == excinfo.value
  </code></pre>
  
  <p>py.test complains that the exception was not raised. If I change <code>yield</code> by <code>return</code>, the code works without any problem. Any ideas?</p>