Repository: google/openhtf

Issue:
No mfg upload and looping ceases when phase raises exception.
In hello_world.py I set loop=True, added mfg inspect key/user and callback, and had a phase raise an exception. Two issues observed:
1) Test stops looping
2) Test doesn't upload result to mfg inspector

python ./hello_world.py --config ./hello_world.yaml
Provide a DUT ID in order to start the test.
test
What's the widget type?
asdf
ERROR:root:Thread raised an exception: set_measurements
Traceback (most recent call last):
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/threads.py", line 51, in run
    self._ThreadProc()
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/exe/phasemanager.py", line 80, in _ThreadProc
    self._phase_result = self._phase(self._phase_data)
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/__init__.py", line 97, in **call**
    return self.func(phase_data, *_plug_kwargs)
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/monitors.py", line 95, in MonitoredPhaseFunc
    return phase_func(phase_data, *args, *_kwargs)
  File "./hello_world.py", line 70, in set_measurements
    raise FooException('Foo Exception')
FooException: Foo Exception
Exception in thread set_measurements:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in **bootstrap_inner
    self.run()
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/threads.py", line 51, in run
    self._ThreadProc()
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/exe/phasemanager.py", line 80, in _ThreadProc
    self._phase_result = self._phase(self._phase_data)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/__init**.py", line 97, in **call**
    return self.func(phase_data, *_plug_kwargs)
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/monitors.py", line 95, in MonitoredPhaseFunc
    return phase_func(phase_data, *args, *_kwargs)
  File "./hello_world.py", line 70, in set_measurements
    raise FooException('Foo Exception')
FooException: Foo Exception

DEBUG:hello_world.py:Finishing test execution with state State.ERROR.
2016-02-11 19:23:26,549 - ERROR - Failed to execute test.
Traceback (most recent call last):
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/exe/**init**.py", line 138, in _RunTestLoop
    self.test.OutputTestRecord(self._test_state.GetFinishedRecord())
  File "/home/venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/__init__.py", line 150, in OutputTestRecord
    output_cb(test_record)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/**init**.py", line 35, in **call**
    test_record).SerializeToString())
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/mfg_inspector.py", line 249, in TestRunFromTestRecord
    mangled_parameters = _ExtractParameters(record, testrun, used_parameter_names)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/mfg_inspector.py", line 170, in _ExtractParameters
    value = phase.measured_values[name]
KeyError: 'level_all'
ERROR:root:Thread raised an exception: Thread-1
Traceback (most recent call last):
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/threads.py", line 51, in run
    self._ThreadProc()
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/exe/__init__.py", line 113, in _ThreadProc
    self._RunTestLoop()
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/threads.py", line 35, in _proc
    fn(_args, *_kwargs)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/exe/__init__.py", line 138, in _RunTestLoop
    self.test.OutputTestRecord(self._test_state.GetFinishedRecord())
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/__init__.py", line 150, in OutputTestRecord
    output_cb(test_record)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/**init**.py", line 35, in **call**
    test_record).SerializeToString())
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/mfg_inspector.py", line 249, in TestRunFromTestRecord
    mangled_parameters = _ExtractParameters(record, testrun, used_parameter_names)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/mfg_inspector.py", line 170, in _ExtractParameters
    value = phase.measured_values[name]
KeyError: 'level_all'
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/threads.py", line 51, in run
    self._ThreadProc()
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/exe/__init__.py", line 113, in _ThreadProc
    self._RunTestLoop()
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/util/threads.py", line 35, in _proc
    fn(_args, *_kwargs)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/exe/__init__.py", line 138, in _RunTestLoop
    self.test.OutputTestRecord(self._test_state.GetFinishedRecord())
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/__init__.py", line 150, in OutputTestRecord
    output_cb(test_record)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/**init**.py", line 35, in **call**
    test_record).SerializeToString())
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/mfg_inspector.py", line 249, in TestRunFromTestRecord
    mangled_parameters = _ExtractParameters(record, testrun, used_parameter_names)
  File "/home//venv/local/lib/python2.7/site-packages/openhtf-1.0-py2.7.egg/openhtf/io/output/mfg_inspector.py", line 170, in _ExtractParameters
    value = phase.measured_values[name]
KeyError: 'level_all'



Discussion:

Resolving patch:
diff --git a/openhtf/io/output/mfg_inspector.py b/openhtf/io/output/mfg_inspector.py
--- a/openhtf/io/output/mfg_inspector.py
+++ b/openhtf/io/output/mfg_inspector.py
@@ -155,11 +155,12 @@ def _ExtractParameters(record, testrun, used_parameter_names):
 
     _ExtractAttachments(phase, testrun, used_parameter_names)
     for name, measurement in sorted(phase.measurements.items()):
-      while name in used_parameter_names:
-        name += '_'
-      used_parameter_names.add(name)
+      tr_name = name
+      while tr_name in used_parameter_names:
+        tr_name += '_'
+      used_parameter_names.add(tr_name)
       testrun_param = testrun.test_parameters.add()
-      testrun_param.name = name
+      testrun_param.name = tr_name
       testrun_param.status = (
           testrun_pb2.PASS if measurement.outcome else testrun_pb2.FAIL)
       if measurement.docstring:
@@ -167,6 +168,9 @@ def _ExtractParameters(record, testrun, used_parameter_names):
       if measurement.units:
         testrun_param.unit_code = UOM_CODE_MAP[measurement.units.uom_code]
 
+      if name not in phase.measured_values:
+        testrun_param.status = testrun_pb2.ERROR
+        continue
       value = phase.measured_values[name]
       if measurement.dimensions is None:
         # Just a plain ol' value.


Test patch: