[openstack-dev] [infra][neutron]SystemExit() vs sys.exit()?

Kevin L. Mitchell kevin.mitchell at rackspace.com
Thu May 1 19:09:11 UTC 2014


On Thu, 2014-05-01 at 18:41 +0000, Paul Michali (pcm) wrote:
> So, I tried to reproduce, but I actually see the same results with
> both of these. However, they both show the issue I was hitting,
> namely, I got no information on where the failure was located:

So, this is pretty much by design.  A SystemExit extends BaseException,
rather than Exception.  The tests will catch Exception, but not
typically BaseException, as you generally want things like ^C to work
(raises a different BaseException).  So, your tests that might possibly
trigger a SystemExit (or sys.exit()) that you don't want to actually
exit from must either explicitly catch the SystemExit or—assuming the
code uses sys.exit()—must mock sys.exit() to inhibit the normal exit
behavior.

(Also, because SystemExit is the exception that is usually raised for a
normal exit condition, the traceback would not typically be printed, as
that could confuse users; no one expects a successfully executed script
to print a traceback, after all :)
-- 
Kevin L. Mitchell <kevin.mitchell at rackspace.com>
Rackspace




More information about the OpenStack-dev mailing list