Commit 002b2148 authored by Stefan Behnel's avatar Stefan Behnel

minor cleanups in test runner, flush output regularly to avoid incomplete output on crashes

parent 1682b7c8
...@@ -750,14 +750,14 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -750,14 +750,14 @@ class CythonRunTestCase(CythonCompileTestCase):
tests.run(result) tests.run(result)
run_forked_test(result, run_test, self.shortDescription(), self.fork) run_forked_test(result, run_test, self.shortDescription(), self.fork)
def run_forked_test(result, run_func, test_name, fork=True): def run_forked_test(result, run_func, test_name, fork=True):
if not fork or sys.version_info[0] >= 3 or not hasattr(os, 'fork'): if not fork or sys.version_info[0] >= 3 or not hasattr(os, 'fork'):
run_func(result) run_func(result)
sys.stdout.flush()
sys.stderr.flush()
gc.collect() gc.collect()
return return
module_name = test_name.split()[-1]
# fork to make sure we do not keep the tested module loaded # fork to make sure we do not keep the tested module loaded
result_handle, result_file = tempfile.mkstemp() result_handle, result_file = tempfile.mkstemp()
os.close(result_handle) os.close(result_handle)
...@@ -770,6 +770,8 @@ def run_forked_test(result, run_func, test_name, fork=True): ...@@ -770,6 +770,8 @@ def run_forked_test(result, run_func, test_name, fork=True):
try: try:
partial_result = PartialTestResult(result) partial_result = PartialTestResult(result)
run_func(partial_result) run_func(partial_result)
sys.stdout.flush()
sys.stderr.flush()
gc.collect() gc.collect()
except Exception: except Exception:
if tests is None: if tests is None:
...@@ -798,7 +800,7 @@ def run_forked_test(result, run_func, test_name, fork=True): ...@@ -798,7 +800,7 @@ def run_forked_test(result, run_func, test_name, fork=True):
if result_code & 255: if result_code & 255:
raise Exception("Tests in module '%s' were unexpectedly killed by signal %d"% raise Exception("Tests in module '%s' were unexpectedly killed by signal %d"%
(module_name, result_code & 255)) (module_name, result_code & 255))
result_code = result_code >> 8 result_code >>= 8
if result_code in (0,1): if result_code in (0,1):
input = open(result_file, 'rb') input = open(result_file, 'rb')
try: try:
...@@ -947,15 +949,22 @@ class CythonPyregrTestCase(CythonRunTestCase): ...@@ -947,15 +949,22 @@ class CythonPyregrTestCase(CythonRunTestCase):
def run_doctest(module, verbosity=None): def run_doctest(module, verbosity=None):
return self._run_doctest(result, module) return self._run_doctest(result, module)
backup = (support.run_unittest, support.run_doctest)
support.run_unittest = run_unittest support.run_unittest = run_unittest
support.run_doctest = run_doctest support.run_doctest = run_doctest
try: try:
module = __import__(self.module) try:
if hasattr(module, 'test_main'): sys.stdout.flush() # helps in case of crashes
module.test_main() module = __import__(self.module)
except (unittest.SkipTest, support.ResourceDenied): sys.stdout.flush() # helps in case of crashes
result.addSkip(self, 'ok') if hasattr(module, 'test_main'):
module.test_main()
sys.stdout.flush() # helps in case of crashes
except (unittest.SkipTest, support.ResourceDenied):
result.addSkip(self, 'ok')
finally:
support.run_unittest, support.run_doctest = backup
run_forked_test(result, run_test, self.shortDescription(), self.fork) run_forked_test(result, run_test, self.shortDescription(), self.fork)
......
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