def run_test(self): context.current_testresult().log_record(EnumLogLevel.APPCRASH, "App Crash", attachments={ 'QQ12e6.dmp': __file__, 'QQ12e6.txt': __file__ })
def acquire_resource(self, res_type, res_group=None, condition=None): """申请资源 :param res_type: 资源类型 :type res_type: str :param res_group: 资源分组 :type res_type: str :param condition: 资源属性匹配 :type condition: dict :returns: 资源 :rtypes: dict """ tc = context.current_testresult() try: resource = self._backend.acquire_resource(self._id, res_type, res_group, condition) except ResourceNotAvailable: if tc: tc.log_record(EnumLogLevel.RESNOTREADY, "acquire resource (res_type:%s, res_group:%s, condition:%s) failed" % (res_type, res_group, condition)) raise else: if tc: extra = {} extra["res_type"] = res_type if not isinstance(resource, dict): raise ValueError("Resource record should be a dictionary") if "id" not in resource: raise ValueError("Resource record should be a dictionary with key 'id'") extra["resource_id"] = resource["id"] tc.log_record(EnumLogLevel.RESOURCE, "acquire resource (res_type:%s, res_group:%s, condition:%s) successfully" % (res_type, res_group, condition), extra) return resource
def emit(self, log_record): '''Log Handle 必须实现此函数 ''' testresult = context.current_testresult() if testresult is None: _streamhandler.emit(log_record) return record = {} if log_record.exc_info: record['traceback'] = ''.join(traceback.format_tb(log_record.exc_info[2])) + '%s: %s' %( log_record.exc_info[0].__name__, log_record.exc_info[1]) testresult.log_record(log_record.levelno, log_record.msg, record)