]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commit
Different approach to indicate failure on SystemExit
authorAngus Lees <gus@inodes.org>
Fri, 15 May 2015 06:21:44 +0000 (16:21 +1000)
committerAngus Lees <gus@inodes.org>
Wed, 24 Jun 2015 23:35:55 +0000 (09:35 +1000)
commitaeca3ccefc4808eedf88681efc11b4ffad710d01
tree8c408c2810af63df52ac986099375fe815aed9cb
parentaf41907e066b11c068ee18fd82b870289e44e25a
Different approach to indicate failure on SystemExit

The handlers added via addOnException can only add further detail and
can't alter the result of the test case.  The previous code called
`self.fail()` on SystemExit, but the resulting AssertionError wasn't
actually caught by the test machinery and escaped out - aborting the
test run and exiting non-zero (good) but without the usual test failure
reporting (details, etc) nor continuing on to the next test case (bad).

This change indicates failure on SystemExit by setting the
`force_failure` attribute to True.  This attribute is checked very late
in the test running process and *does* allow the exception handler to
override the regular test result and indicate a failure "cleanly".

The unittest mocking arms race continues!

While experimenting with one (since abandoned) approach, I observed
different behaviour with sys.exit(1) vs sys.exit(0) (would print failure
stacktrace as expected, but then went on to exit the overall process
with exitcode 0).  Although any exit status behaves correctly with the
final approach taken, this change also adds an explicit unittest
exercising the sys.exit(0) case.

Change-Id: I18767f5757c35b8e9ae8e61fef3d7f786ed56bdb
neutron/tests/base.py
neutron/tests/unit/tests/test_base.py