summaryrefslogtreecommitdiff
path: root/tests/PexpectTestCase.py
diff options
context:
space:
mode:
authorJeff Quast <contact@jeffquast.com>2014-11-24 21:39:41 -0800
committerJeff Quast <contact@jeffquast.com>2014-11-24 21:40:29 -0800
commit82198ab4a856e05dd15beb75149f45358761d516 (patch)
treefcfab3657bf247b6fd79e7cc7cd85fbe49979bd4 /tests/PexpectTestCase.py
parent4382f40f69eb7bdd84f0b46282f2cbbb65c5552b (diff)
downloadpexpect-git-82198ab4a856e05dd15beb75149f45358761d516.tar.gz
Propose test-runner fork prevention scheme
Diffstat (limited to 'tests/PexpectTestCase.py')
-rw-r--r--tests/PexpectTestCase.py13
1 files changed, 13 insertions, 0 deletions
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)