From 82198ab4a856e05dd15beb75149f45358761d516 Mon Sep 17 00:00:00 2001 From: Jeff Quast Date: Mon, 24 Nov 2014 21:39:41 -0800 Subject: Propose test-runner fork prevention scheme --- tests/PexpectTestCase.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/PexpectTestCase.py') diff --git a/tests/PexpectTestCase.py b/tests/PexpectTestCase.py index 9d620f8..307437e 100644 --- a/tests/PexpectTestCase.py +++ b/tests/PexpectTestCase.py @@ -38,6 +38,11 @@ class PexpectTestCase(unittest.TestCase): # programs in this folder executed by spawn(). os.chdir(tests_dir) + # If the pexpect raises an exception after fork(), but before + # exec(), our test runner *also* forks. We prevent this by + # storing our pid and asserting equality on tearDown. + self.pid = os.getpid() + coverage_rc = os.path.join(project_dir, '.coveragerc') os.environ['COVERAGE_PROCESS_START'] = coverage_rc os.environ['COVERAGE_FILE'] = os.path.join(project_dir, '.coverage') @@ -66,6 +71,14 @@ class PexpectTestCase(unittest.TestCase): # restore original working folder os.chdir(self.original_path) + if self.pid != os.getpid(): + # The build server pattern-matches phrase 'Test runner has forked!' + print("Test runner has forked! This means a child process raised " + "an exception before exec() in a test case, the error is " + "more than likely found above this line in stderr.", + file=sys.stderr) + exit(1) + # restore signal handlers for signal_value in self.restore_ignored_signals: signal.signal(signal_value, signal.SIG_IGN) -- cgit v1.2.1