Commit f404ba74 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix forking in runtests.py (ticket #449).

parent c62e213a
...@@ -9,6 +9,7 @@ import shutil ...@@ -9,6 +9,7 @@ import shutil
import unittest import unittest
import doctest import doctest
import operator import operator
import tempfile
try: try:
from StringIO import StringIO from StringIO import StringIO
except ImportError: except ImportError:
...@@ -401,12 +402,12 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -401,12 +402,12 @@ class CythonRunTestCase(CythonCompileTestCase):
return return
# fork to make sure we do not keep the tested module loaded # fork to make sure we do not keep the tested module loaded
input, output = os.pipe() result_handle, result_file = tempfile.mkstemp()
child_id = os.fork() child_id = os.fork()
if not child_id: if not child_id:
result_code = 0 result_code = 0
try: try:
output = os.fdopen(output, 'wb') output = os.fdopen(result_handle, 'wb')
tests = None tests = None
try: try:
partial_result = PartialTestResult(result) partial_result = PartialTestResult(result)
...@@ -423,14 +424,18 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -423,14 +424,18 @@ class CythonRunTestCase(CythonCompileTestCase):
partial_result.addError(tests, sys.exc_info()) partial_result.addError(tests, sys.exc_info())
result_code = 1 result_code = 1
pickle.dump(partial_result.data(), output) pickle.dump(partial_result.data(), output)
except:
import traceback
traceback.print_exc()
finally: finally:
try: output.close() try: output.close()
except: pass except: pass
os._exit(result_code) os._exit(result_code)
try:
cid, result_code = os.waitpid(child_id, 0) cid, result_code = os.waitpid(child_id, 0)
if result_code in (0,1): if result_code in (0,1):
input = os.fdopen(input, 'rb') input = open(result_file, 'rb')
try: try:
PartialTestResult.join_results(result, pickle.load(input)) PartialTestResult.join_results(result, pickle.load(input))
finally: finally:
...@@ -438,14 +443,18 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -438,14 +443,18 @@ class CythonRunTestCase(CythonCompileTestCase):
if result_code: if result_code:
raise Exception("Tests in module '%s' exited with status %d" % raise Exception("Tests in module '%s' exited with status %d" %
(module_name, result_code >> 8)) (module_name, result_code >> 8))
finally:
os.unlink(result_file)
is_private_field = re.compile('^_[^_]').match is_private_field = re.compile('^_[^_]').match
class _FakeClass(object): class _FakeClass(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.shortDescription = lambda x: kwargs.get('module_name') self._shortDescription = kwargs.get('module_name')
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
def shortDescription(self):
return self._shortDescription
try: # Py2.7+ and Py3.2+ try: # Py2.7+ and Py3.2+
from unittest.runner import _TextTestResult from unittest.runner import _TextTestResult
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment