Skip to content

Commit e9d7365

Browse files
authored
Handle skipped phases in ConsoleSummary (#990)
Fixes #982
1 parent 486ac88 commit e9d7365

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

openhtf/output/callbacks/console_summary.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def __call__(self, record):
6767
if not phase_result: # Timeout.
6868
output_lines.append('timeout phase: %s [ran for %.2f sec]' %
6969
(phase.name, phase_time_sec))
70-
elif 'CONTINUE' not in str(phase_result): # Exception.
70+
elif 'CONTINUE' not in str(phase_result) and record.outcome_details:
71+
# Exception.
7172
output_lines.append('%sexception type: %s' %
7273
(self.indent, record.outcome_details[0].code))
7374

test/output/callbacks/callbacks_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import openhtf as htf
2626
from openhtf import util
2727
from examples import all_the_things
28+
from openhtf.core import phase_branches, phase_descriptor, phase_collections, phase_group
2829
from openhtf.output.callbacks import console_summary
2930
from openhtf.output.callbacks import json_factory
3031
from openhtf.output.proto import mfg_event_converter
@@ -176,3 +177,25 @@ def test_outcome_colors(self):
176177
instance = console_summary.ConsoleSummary()
177178
for outcome in htf.test_record.Outcome:
178179
self.assertIn(outcome, instance.color_table)
180+
181+
def test_empty_outcome(self):
182+
"""Console Summary must not crash if phases have been skipped."""
183+
checkpoint = phase_branches.PhaseFailureCheckpoint.all_previous(
184+
"cp", action=phase_descriptor.PhaseResult.FAIL_SUBTEST)
185+
phasegroup = phase_group.PhaseGroup(
186+
lambda: htf.PhaseResult.FAIL_AND_CONTINUE,
187+
lambda: htf.PhaseResult.SKIP,
188+
checkpoint,
189+
)
190+
subtest = phase_collections.Subtest("st", phasegroup)
191+
test = htf.Test(subtest)
192+
193+
result_store = util.NonLocalResult()
194+
def _save_result(test_record):
195+
result_store.result = test_record
196+
test.add_output_callbacks(
197+
console_summary.ConsoleSummary(), _save_result)
198+
199+
test.execute()
200+
assert not any("Traceback" in record.message
201+
for record in result_store.result.log_records)

0 commit comments

Comments
 (0)