def _handle_phase(self, phase): """Handle execution of a single test phase.""" # Make sure we initialize any plugs, this will ignore any that have already # been initialized. self.plug_manager.InitializePlugs(plug.cls for plug in phase.plugs if plug.cls not in self.mock_plugs) for plug_type, plug_value in self.mock_plugs.iteritems(): self.plug_manager.OverridePlug(plug_type, plug_value) # Cobble together a fake phase data to pass to the test phase. We use the # root logger as a logger, our stub plug manager, and a dummy test record # that has None for dut_id and station_id. phasedata = phase_data.PhaseData(logging.getLogger(), self.plug_manager, test_record.TestRecord(None, None)) phase_record = test_record.PhaseRecord(phase.name, phase.code_info) # Actually execute the phase, saving the result in our return value. with phasedata.RecordPhaseTiming(phase, phase_record): try: phase_record.result = phase_executor.PhaseOutcome( phase(phasedata)) except Exception as exc: logging.exception('Exception executing phase %s', phase.name) phase_record.result = phase_executor.PhaseOutcome(exc) return phase_record
def __init__(self, test_data, plug_manager, dut_id, station_id): self._state = self.State.CREATED self.record = test_record.TestRecord( dut_id=dut_id, station_id=station_id, code_info=test_data.code_info, metadata=test_data.metadata) self.logger = logging.getLogger(logs.RECORD_LOGGER) self._record_handler = logs.RecordHandler(self.record) self.logger.addHandler(self._record_handler) self.phase_data = phase_data.PhaseData(self.logger, plug_manager, self.record) self.running_phase_record = None self.pending_phases = list(test_data.phases)
def __init__(self, config, test, plugs, dut_id): station_id = conf.Config().station_id self._state = self.State.CREATED self._config = config self.record = test_record.TestRecord( dut_id=dut_id, station_id=station_id, metadata={ 'code': test.code, 'filename': test.filename, 'docstring': test.docstring }) self.logger = logging.getLogger(test.filename) self.logger.setLevel(logging.DEBUG) # Let the handler do the filtering. self.logger.addHandler(logs.RecordHandler(self.record)) self.phase_data = phase_data.PhaseData(self.logger, config, plugs, self.record) self.running_phase = None self.pending_phases = list(test.phases)