Skip to content

Commit

Permalink
Add failure outcome details when Multidim measurements fail so that t…
Browse files Browse the repository at this point in the history
…he user can check them (e.g. on the console).

PiperOrigin-RevId: 509314086
  • Loading branch information
OpenHTF Owners authored and Copybara-Service committed Feb 13, 2023
1 parent dc22c0c commit 492a5c6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions openhtf/core/test_state.py
Expand Up @@ -79,6 +79,8 @@ class _Infer(enum.Enum):
INFER_MIMETYPE: Literal[_Infer.INFER] = _Infer.INFER
MimetypeT = Union[None, Literal[INFER_MIMETYPE], Text]

# MultiDim measurement failure code.
MULTIDIM_FAIL = 'Multidim Measurement Failure'

class BlankDutIdError(Exception):
"""DUT serial cannot be blank at the end of a test."""
Expand Down Expand Up @@ -447,6 +449,30 @@ def finalize_from_phase_outcome(
)
self._finalize(test_record.Outcome.FAIL)

def maybe_add_outcome_details_from_phases_multidim_measurements(self):
"""Add additional outcome details for failed multidim measurements."""
indent = ' '
for phase in self.test_record.phases:
if phase.outcome == test_record.PhaseOutcome.FAIL:
for name, measurement in phase.measurements.items():
if (
measurement.outcome != measurements.Outcome.PASS
and measurement.dimensions
):
message = [
'%sfailed_item: %s (%s)' % (indent, name, measurement.outcome)
]
message.append(
'%smeasured_value: %s'
% (indent * 2, measurement.measured_value)
)
message.append('%svalidators:' % (indent * 2))
for validator in measurement.validators:
message.append('%svalidator: %s' % (indent * 3, str(validator)))
self.test_record.add_outcome_details(
MULTIDIM_FAIL, '\n'.join(message)
)

def finalize_normally(self) -> None:
"""Mark the state as finished.
Expand All @@ -462,6 +488,8 @@ def finalize_normally(self) -> None:
self._finalize(test_record.Outcome.PASS)
elif any(
phase.outcome == test_record.PhaseOutcome.FAIL for phase in phases):
# Look for multidim failures to add to outcome details.
self.maybe_add_outcome_details_from_phases_multidim_measurements()
# Any FAIL phase results in a test failure.
self._finalize(test_record.Outcome.FAIL)
elif all(
Expand Down

0 comments on commit 492a5c6

Please sign in to comment.