Commit b3fa3005 authored by Stefan Behnel's avatar Stefan Behnel

try to make test runner more robust

parent d66375b2
...@@ -891,9 +891,10 @@ def run_forked_test(result, run_func, test_name, fork=True): ...@@ -891,9 +891,10 @@ def run_forked_test(result, run_func, test_name, fork=True):
child_id = os.fork() child_id = os.fork()
if not child_id: if not child_id:
result_code = 0 result_code = 0
output = None
try: try:
try: try:
tests = None tests = partial_result = None
try: try:
partial_result = PartialTestResult(result) partial_result = PartialTestResult(result)
run_func(partial_result) run_func(partial_result)
...@@ -901,6 +902,8 @@ def run_forked_test(result, run_func, test_name, fork=True): ...@@ -901,6 +902,8 @@ def run_forked_test(result, run_func, test_name, fork=True):
sys.stderr.flush() sys.stderr.flush()
gc.collect() gc.collect()
except Exception: except Exception:
result_code = 1
if partial_result is not None:
if tests is None: if tests is None:
# importing failed, try to fake a test class # importing failed, try to fake a test class
tests = _FakeClass( tests = _FakeClass(
...@@ -908,14 +911,20 @@ def run_forked_test(result, run_func, test_name, fork=True): ...@@ -908,14 +911,20 @@ def run_forked_test(result, run_func, test_name, fork=True):
_shortDescription=test_name, _shortDescription=test_name,
module_name=None) module_name=None)
partial_result.addError(tests, sys.exc_info()) partial_result.addError(tests, sys.exc_info())
result_code = 1
output = open(result_file, 'wb') output = open(result_file, 'wb')
pickle.dump(partial_result.data(), output) pickle.dump(partial_result.data(), output)
except: except:
traceback.print_exc() traceback.print_exc()
finally: finally:
try: output.close() try: sys.stderr.flush()
except: pass
try: sys.stdout.flush()
except: pass except: pass
try:
if output is not None:
output.close()
except:
pass
os._exit(result_code) os._exit(result_code)
try: try:
......
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