提交 861685d3 编写于 作者: C Cleber Rosa

test states: proper support for INTERRUPTED tests

This adds proper handling for tests that finish with state as INTERRUPTED.

A test can be interrupted in two different ways: if user hits CTRL+C while
the test is running, or if the test process receives a SIGINT.

This makes it possible for a (skilled) user to interrupt a single long running
test while not canceling the job completely.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 59588ae3
......@@ -154,6 +154,7 @@ class TermSupport(object):
self.PASS = self.COLOR_GREEN
self.SKIP = self.COLOR_YELLOW
self.FAIL = self.COLOR_RED
self.INTERRUPT = self.COLOR_RED
self.ERROR = self.COLOR_RED
self.WARN = self.COLOR_YELLOW
self.PARTIAL = self.COLOR_YELLOW
......@@ -176,6 +177,7 @@ class TermSupport(object):
self.PASS = ''
self.SKIP = ''
self.FAIL = ''
self.INTERRUPT = ''
self.ERROR = ''
self.WARN = ''
self.PARTIAL = ''
......@@ -256,6 +258,14 @@ class TermSupport(object):
"""
return self.MOVE_BACK + self.ERROR + 'ERROR' + self.ENDC
def interrupt_str(self):
"""
Print an interrupt string (red colored).
If the output does not support colors, just return the original string.
"""
return self.MOVE_BACK + self.INTERRUPT + 'INTERRUPT' + self.ENDC
def warn_str(self):
"""
Print an warning string (yellow colored).
......@@ -414,7 +424,8 @@ class View(object):
'ERROR': self._log_ui_status_error,
'FAIL': self._log_ui_status_fail,
'SKIP': self._log_ui_status_skip,
'WARN': self._log_ui_status_warn}
'WARN': self._log_ui_status_warn,
'INTERRUPTED': self._log_ui_status_interrupt}
mapping[status](state['time_elapsed'])
def set_tests_info(self, info):
......@@ -530,6 +541,15 @@ class View(object):
normal_error_msg = term_support.error_str() + " (%.2f s)" % t_elapsed
self._log_ui_error_base(normal_error_msg)
def _log_ui_status_interrupt(self, t_elapsed):
"""
Log an INTERRUPT status message for a given operation.
:param t_elapsed: Time it took for the operation to complete.
"""
normal_error_msg = term_support.interrupt_str() + " (%.2f s)" % t_elapsed
self._log_ui_error_base(normal_error_msg)
def _log_ui_status_fail(self, t_elapsed):
"""
Log a FAIL status message for a given operation.
......
......@@ -126,6 +126,7 @@ class TestResult(object):
self.failed = []
self.skipped = []
self.warned = []
self.interrupted = []
# Where this results intends to write to. Convention is that a dash (-)
# means stdout, and stdout is a special output that can be exclusively
......@@ -142,7 +143,7 @@ class TestResult(object):
"""
valid_results_count = (len(self.passed) + len(self.errors) +
len(self.failed) + len(self.warned) +
len(self.skipped))
len(self.skipped) + len(self.interrupted))
other_skipped_count = self.tests_total - valid_results_count
for i in xrange(other_skipped_count):
self.skipped.append({})
......@@ -224,6 +225,15 @@ class TestResult(object):
"""
self.warned.append(state)
def add_interrupt(self, state):
"""
Called when a test is interrupted by the user.
:param state: result of :class:`avocado.test.Test.get_state`.
:type state: dict
"""
self.interrupted.append(state)
def check_test(self, state):
"""
Called once for a test to check status and report.
......@@ -234,7 +244,8 @@ class TestResult(object):
'ERROR': self.add_error,
'FAIL': self.add_fail,
'TEST_NA': self.add_skip,
'WARN': self.add_warn}
'WARN': self.add_warn,
'INTERRUPTED': self.add_interrupt}
add = status_map[state['status']]
add(state)
self.end_test(state)
......@@ -271,6 +282,7 @@ class HumanTestResult(TestResult):
self.stream.notify(event="message", msg="FAIL : %d" % len(self.failed))
self.stream.notify(event="message", msg="SKIP : %d" % len(self.skipped))
self.stream.notify(event="message", msg="WARN : %d" % len(self.warned))
self.stream.notify(event="message", msg="INTERRUPT : %d" % len(self.interrupted))
self.stream.notify(event="message", msg="TIME : %.2f s" % self.total_time)
def start_test(self, state):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册