Commit 533aa388 authored by Stefan Behnel's avatar Stefan Behnel

Support test skipping also in run tests.

parent b1f7ef11
...@@ -65,6 +65,8 @@ except ImportError: ...@@ -65,6 +65,8 @@ except ImportError:
try: try:
from unittest import SkipTest from unittest import SkipTest
except ImportError: except ImportError:
class SkipTest(Exception): # don't raise, only provided to allow except-ing it!
pass
def skip_test(reason): def skip_test(reason):
print("Skipping test: %s" % reason) print("Skipping test: %s" % reason)
else: else:
...@@ -1025,7 +1027,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -1025,7 +1027,7 @@ class CythonCompileTestCase(unittest.TestCase):
newext = fixer(extension) newext = fixer(extension)
if newext is EXCLUDE_EXT: if newext is EXCLUDE_EXT:
return skip_test("Test '%s' excluded due to tags '%s'" % ( return skip_test("Test '%s' excluded due to tags '%s'" % (
self.name, ', '.join(self.tags))) self.name, ', '.join(self.tags.get('tag', ''))))
extension = newext or extension extension = newext or extension
if self.language == 'cpp': if self.language == 'cpp':
extension.language = 'c++' extension.language = 'c++'
...@@ -1174,7 +1176,7 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -1174,7 +1176,7 @@ class CythonRunTestCase(CythonCompileTestCase):
try: try:
self.success = False self.success = False
ext_so_path = self.runCompileTest() ext_so_path = self.runCompileTest()
failures, errors = len(result.failures), len(result.errors) failures, errors, skipped = len(result.failures), len(result.errors), len(result.skipped)
if not self.cython_only and ext_so_path is not None: if not self.cython_only and ext_so_path is not None:
self.run_tests(result, ext_so_path) self.run_tests(result, ext_so_path)
if failures == len(result.failures) and errors == len(result.errors): if failures == len(result.failures) and errors == len(result.errors):
...@@ -1182,6 +1184,9 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -1182,6 +1184,9 @@ class CythonRunTestCase(CythonCompileTestCase):
self.success = True self.success = True
finally: finally:
check_thread_termination() check_thread_termination()
except SkipTest as exc:
result.addSkip(self, str(exc))
result.stopTest(self)
except Exception: except Exception:
result.addError(self, sys.exc_info()) result.addError(self, sys.exc_info())
result.stopTest(self) result.stopTest(self)
...@@ -1363,17 +1368,18 @@ class PartialTestResult(_TextTestResult): ...@@ -1363,17 +1368,18 @@ class PartialTestResult(_TextTestResult):
def data(self): def data(self):
self.strip_error_results(self.failures) self.strip_error_results(self.failures)
self.strip_error_results(self.errors) self.strip_error_results(self.errors)
return (self.failures, self.errors, self.testsRun, return (self.failures, self.errors, self.skipped, self.testsRun,
self.stream.getvalue()) self.stream.getvalue())
def join_results(result, data): def join_results(result, data):
"""Static method for merging the result back into the main """Static method for merging the result back into the main
result object. result object.
""" """
failures, errors, tests_run, output = data failures, errors, skipped, tests_run, output = data
if output: if output:
result.stream.write(output) result.stream.write(output)
result.errors.extend(errors) result.errors.extend(errors)
result.skipped.extend(skipped)
result.failures.extend(failures) result.failures.extend(failures)
result.testsRun += tests_run result.testsRun += tests_run
......
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