Exemplo n.º 1
0
    def _handle_phase(self, phase_desc):
        """Handle execution of a single test phase."""
        logs.configure_logging()
        self._initialize_plugs(phase_plug.cls
                               for phase_plug in phase_desc.plugs)

        # Cobble together a fake TestState to pass to the test phase.
        test_options = test_descriptor.TestOptions()
        with mock.patch('openhtf.plugs.PlugManager',
                        new=lambda _, __: self.plug_manager):
            test_state_ = test_state.TestState(
                openhtf.TestDescriptor((phase_desc, ), phase_desc.code_info,
                                       {}), 'Unittest:StubTest:UID',
                test_options)
            test_state_.mark_test_started()

        # Actually execute the phase, saving the result in our return value.
        executor = phase_executor.PhaseExecutor(test_state_)
        # Log an exception stack when a Phase errors out.
        with mock.patch.object(phase_executor.PhaseExecutorThread,
                               '_log_exception',
                               side_effect=logging.exception):
            # Use _execute_phase_once because we want to expose all possible outcomes.
            executor._execute_phase_once(phase_desc,
                                         is_last_repeat=False,
                                         run_with_profiling=False)
        return test_state_.test_record.phases[-1]
Exemplo n.º 2
0
    def _handle_phase(self, phase_desc):
        """Handle execution of a single test phase."""
        self._initialize_plugs(phase_plug.cls
                               for phase_plug in phase_desc.plugs)

        # Cobble together a fake TestState to pass to the test phase.
        with mock.patch('openhtf.plugs.PlugManager',
                        new=lambda _, __: self.plug_manager):
            test_state_ = test_state.TestState(
                openhtf.TestDescriptor((phase_desc, ), phase_desc.code_info,
                                       {}), 'Unittest:StubTest:UID')
            test_state_.mark_test_started()

        # Actually execute the phase, saving the result in our return value.
        with test_state_.running_phase_context(phase_desc) as phase_state:
            try:
                phase_state.result = phase_executor.PhaseExecutionOutcome(
                    phase_desc(test_state_))
            except Exception:  # pylint:disable=broad-except
                logging.exception('Exception executing phase %s',
                                  phase_desc.name)
                phase_state.result = phase_executor.PhaseExecutionOutcome(
                    phase_executor.ExceptionInfo(*sys.exc_info()))

        return phase_state.phase_record
Exemplo n.º 3
0
    def _handle_phase(self, phase_desc):
        """Handle execution of a single test phase."""
        self._initialize_plugs(phase_plug.cls
                               for phase_plug in phase_desc.plugs)

        # Cobble together a fake TestState to pass to the test phase.
        with mock.patch('openhtf.plugs.PlugManager',
                        new=lambda _, __: self.plug_manager):
            test_state_ = test_state.TestState(
                openhtf.TestDescriptor((phase_desc, ), phase_desc.code_info,
                                       {}), 'Unittest:StubTest:UID')
            test_state_.mark_test_started()

        # Actually execute the phase, saving the result in our return value.
        executor = phase_executor.PhaseExecutor(test_state_)
        # Use _execute_phase_once because we want to expose all possible outcomes.
        executor._execute_phase_once(phase_desc, is_last_repeat=False)
        return test_state_.test_record.phases[-1]
Exemplo n.º 4
0
  def _handle_phase(self, phase_desc):
    """Handle execution of a single test phase."""
    diagnoses_lib.check_for_duplicate_results(iter([phase_desc]), [])
    logs.configure_logging()
    self._initialize_plugs(phase_plug.cls for phase_plug in phase_desc.plugs)

    # Cobble together a fake TestState to pass to the test phase.
    test_options = test_descriptor.TestOptions()
    with mock.patch(
        'openhtf.plugs.PlugManager', new=lambda _, __: self.plug_manager):
      test_state_ = test_state.TestState(
          openhtf.TestDescriptor(
              phase_collections.PhaseSequence((phase_desc,)),
              phase_desc.code_info, {}), 'Unittest:StubTest:UID', test_options)
      test_state_.mark_test_started()

    test_state_.user_defined_state.update(self.phase_user_defined_state)
    for diag in self.phase_diagnoses:
      test_state_.diagnoses_manager._add_diagnosis(diag)  # pylint: disable=protected-access
      test_state_.test_record.add_diagnosis(diag)

    # Save the test_state to the last_test_case attribute to give it access to
    # the underlying state.
    self.test_case.last_test_state = test_state_

    # Actually execute the phase, saving the result in our return value.
    executor = phase_executor.PhaseExecutor(test_state_)
    # Log an exception stack when a Phase errors out.
    with mock.patch.object(
        phase_executor.PhaseExecutorThread,
        '_log_exception',
        side_effect=logging.exception):
      # Use _execute_phase_once because we want to expose all possible outcomes.
      phase_result, _ = executor._execute_phase_once(
          phase_desc,
          is_last_repeat=False,
          run_with_profiling=False,
          subtest_rec=None)

    if phase_result.raised_exception:
      failure_message = phase_result.phase_result.get_traceback_string()
    else:
      failure_message = None
    return test_state_.test_record.phases[-1], failure_message