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]
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) return test_state_.test_record.phases[-1]
def configure(self, **kwargs): """Update test-wide configuration options. See TestOptions for docs.""" # These internally ensure they are safe to call multiple times with no weird # side effects. known_args, _ = create_arg_parser(add_help=True).parse_known_args() if known_args.config_help: sys.stdout.write(conf.help_text) sys.exit(0) logs.configure_logging() for key, value in six.iteritems(kwargs): setattr(self._test_options, key, value)
def _handle_phase(self, phase_desc): """Handle execution of a single test phase.""" phase_descriptor.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.object(plugs, 'PlugManager', new=lambda _, __: self.plug_manager): test_state_ = test_state.TestState( test_descriptor.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_) profile_filepath = self.test_case.get_profile_filepath() # 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, profile_stats = executor._execute_phase_once( phase_desc, is_last_repeat=False, run_with_profiling=profile_filepath, subtest_rec=None) if profile_filepath is not None: _merge_stats(profile_stats, profile_filepath) 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