diff --git a/openhtf/core/monitors.py b/openhtf/core/monitors.py index 2d16ef15d..1d03f2223 100644 --- a/openhtf/core/monitors.py +++ b/openhtf/core/monitors.py @@ -84,7 +84,9 @@ def get_value(self) -> Any: else: # Only pass in args that the monitor phase takes. kwargs = { - arg: val for arg, val in self.extra_kwargs if arg in argspec_args + arg: val + for arg, val in self.extra_kwargs.items() + if arg in argspec_args } return self.monitor_desc.with_args(**kwargs)(self.test_state) diff --git a/test/core/monitors_test.py b/test/core/monitors_test.py index a439d5a49..8b76d5059 100644 --- a/test/core/monitors_test.py +++ b/test/core/monitors_test.py @@ -20,6 +20,7 @@ from openhtf import plugs from openhtf.core import base_plugs from openhtf.core import monitors +from openhtf.core import phase_descriptor class EmptyPlug(base_plugs.BasePlug): @@ -96,3 +97,22 @@ def phase(test): first_meas[0], 100, msg='At time 0, there should be a call made.') self.assertEqual( 2, first_meas[1], msg="And it should be the monitor func's return val") + + def test_get_value_with_extra_kwargs(self): + """Monitor without **kwargs handles a phase carrying extra_kwargs. + + A phase that has been parameterized with PhaseDescriptor.with_args() carries + its kwargs in extra_kwargs. The monitor thread forwards those kwargs to the + monitor function, keeping only the arguments the monitor accepts. This used + to iterate over the extra_kwargs dict directly (yielding keys) and unpack + each key into two names, raising `ValueError: too many values to unpack`. + """ + + def monitor_func(test): + del test # Unused. + return 1 + + monitor_thread = monitors._MonitorThread( + 'meas', phase_descriptor.PhaseDescriptor(monitor_func), + {'port': 1234}, self.test_state, 1000) + self.assertEqual(1, monitor_thread.get_value())