title: Is it possible to test a function which uses `os._exit()`?
body: <p>I want to test that a function executes <code>os._exit(2)</code> on fail. I have seen many solutions with <code>sys.exit()</code> using <code>SystemExit</code>. I have read both the <a href="https://docs.python.org/3/library/os.html#os._exit" rel="nofollow noreferrer">Python3</a> and the <a href="https://docs.python.org/2/library/os.html#os._exit" rel="nofollow noreferrer">Python2</a> documentation and it seems that <code>os._exit()</code> doesn't use <code>SystemExit</code></p>
  
  <p>Nevertheless, I have tried <a href="https://stackoverflow.com/questions/15672151/is-it-possible-for-a-unit-test-to-assert-that-a-method-calls-sys-exit">this</a> in case it was a misunderstanding of the documentation on my side, but it just exits nosetest, it's not even a test failure :</p>
  
  <pre><code>make: *** [test] Error 2
  </code></pre>
  
  <p>This is probably due to the function calling <code>os._exit(2)</code></p>