擅长:python、mysql、java
<p>您可以尝试捕获<a href="http://docs.python.org/library/exceptions.html" rel="noreferrer">SystemExit</a>异常。当有人调用<code>sys.exit()</code>时,它会被引发。</p>
<pre><code>with self.assertRaises(SystemExit):
myFunctionThatSometimesCallsSysExit()
</code></pre>