]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
SystemExit is ok for child processes
authorAngus Lees <gus@inodes.org>
Tue, 21 Apr 2015 01:00:04 +0000 (11:00 +1000)
committerAngus Lees <gus@inodes.org>
Wed, 13 May 2015 06:56:52 +0000 (16:56 +1000)
DietTestCase catches SystemExit while running tests, interprets it as a
test failure, and then carry on with the next test (without exiting).
This greatly upsets forked child python processes, which may call exit()
legitimately, and expect that to result in process exit.

This change re-raises the SystemExit if the current process ID is not
the original pid.

Change-Id: Ia39a350b562b2856b5588cd73826afb3d072554f

neutron/tests/base.py

index 0e1c8a07959305222be552bc3932477b352ac315..87f820cc42385187f86097dbebd7af9ea58e559d 100644 (file)
@@ -159,9 +159,13 @@ class DietTestCase(testtools.TestCase):
             self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
 
         self.addOnException(self.check_for_systemexit)
+        self.orig_pid = os.getpid()
 
     def check_for_systemexit(self, exc_info):
         if isinstance(exc_info[1], SystemExit):
+            if os.getpid() != self.orig_pid:
+                # Subprocess - let it just exit
+                raise
             self.fail("A SystemExit was raised during the test. %s"
                       % traceback.format_exception(*exc_info))