diff --git a/openhtf/core/measurements.py b/openhtf/core/measurements.py index e8cfd36d8..9dbbc5a6e 100644 --- a/openhtf/core/measurements.py +++ b/openhtf/core/measurements.py @@ -63,6 +63,7 @@ def WidgetTestPhase(test): import enum import functools import logging +import time import typing from typing import Any, Callable, Dict, Iterator, List, Optional, Text, Tuple, Union @@ -189,6 +190,7 @@ class Measurement(object): outcome: One of the Outcome() enumeration values, starting at UNSET. marginal: A bool flag indicating if this measurement is marginal if the outcome is PASS. + set_time_millis: The time the measurement is set in milliseconds. _cached: A cached dict representation of this measurement created initially during as_base_types and updated in place to save allocation time. """ @@ -214,6 +216,7 @@ class Measurement(object): _notification_cb = attr.ib(type=Optional[Callable[[], None]], default=None) outcome = attr.ib(type=Outcome, default=Outcome.UNSET) marginal = attr.ib(type=bool, default=False) + set_time_millis = attr.ib(type=int, default=None) # Runtime cache to speed up conversions. _cached = attr.ib(type=Optional[Dict[Text, Any]], default=None) @@ -845,6 +848,7 @@ def __setitem__(self, name: Text, value: Any) -> None: 'Cannot set dimensioned measurement without indices') m.measured_value.set(value) m.notify_value_set() + m.set_time_millis = util.time_millis() def __getitem__(self, name: Text) -> Any: self._assert_valid_key(name) diff --git a/test/core/diagnoses_test.py b/test/core/diagnoses_test.py index 25814dfec..79a9aa0e1 100644 --- a/test/core/diagnoses_test.py +++ b/test/core/diagnoses_test.py @@ -1164,6 +1164,7 @@ def check_record_diagnoser(phase_record): is_value_set=True, stored_value=True, cached_value=True), + set_time_millis=phase_record.measurements['pass_measure'].set_time_millis, cached=mock.ANY), phase_record.measurements['pass_measure']) self.assertEqual( htf.Measurement( @@ -1175,6 +1176,7 @@ def check_record_diagnoser(phase_record): stored_value=False, cached_value=False), validators=[is_true], + set_time_millis=phase_record.measurements['fail_measure'].set_time_millis, cached=mock.ANY), phase_record.measurements['fail_measure']) return None