def beforeTest(self): self.current_sample = Sample( test_case=self.test_info["test_case"], test_suite=self.test_info["suite_name"], start_time=time.time(), status="SKIPPED") self.current_sample.extras.update({ "file": self.test_info["test_file"], "full_name": self.test_info["test_fqn"], "description": self.test_info["description"] }) module_fqn_parts = self.test_info["module_fqn"].split('.') for item in module_fqn_parts[:-1]: self.current_sample.path.append(PathComponent("package", item)) self.current_sample.path.append(PathComponent("module", module_fqn_parts[-1])) if "." in self.test_info["class_method"]: # TestClass.test_method class_name, method_name = self.test_info["class_method"].split('.')[:2] self.current_sample.path.extend([ PathComponent("class", class_name), PathComponent("method", method_name)]) else: # test_func self.current_sample.path.append(PathComponent("func", self.test_info["class_method"])) self.log.debug("Test method path: %r", self.current_sample.path) self.test_count += 1
def _fill_sample(self, report, call, item, status): filename, lineno, _ = report.location if self._sample is None: self._sample = Sample() self._sample.test_case = item.name self._sample.test_suite = item.module.__name__ self._sample.start_time = call.start self._sample.extras = {"filename": filename, "lineno": lineno} self._sample.status = status self._sample.duration = time.time() - self._sample.start_time if call.excinfo is not None: self._sample.error_msg = call.excinfo.exconly().strip() self._sample.error_trace = "\n".join( traceback.format_tb(call.excinfo.tb)).strip() if call.excinfo.errisinstance(AssertionError): self._sample.add_assertion(call.excinfo.exconly(), { 'args': '', 'kwargs': '' }) self._sample.set_assertion_failed( call.excinfo.exconly(), str(call.excinfo.value), str(call.excinfo.getrepr(style="native")))
def _get_subsamples(self): recording = self._pop_events() sample = Sample() extr = ApiritifSampleExtractor() trace = extr.parse_recording(recording, sample) toplevel_sample = trace[0].to_dict() self._filter([toplevel_sample]) return toplevel_sample
def __init__(self, writer, index, outfile_name): super(SampleGenerator, self).__init__(target=self._write_sample) self.writer = writer self.index = index self.outfile_name = outfile_name self.sample = Sample(start_time=index, duration=index, test_case="Generator %s" % index)
def _get_subsamples(self): recording = self._pop_events() sample = Sample() extr = ApiritifSampleExtractor() trace = extr.parse_recording(recording, sample) subsamples = trace[0].to_dict()['subsamples'] self._filter(subsamples) return subsamples
def _fill_sample(self, report, call, item, status): filename, lineno, _ = report.location if self._sample is None: self._sample = Sample() self._sample.test_case = item.name self._sample.test_suite = item.module.__name__ self._sample.start_time = call.start self._sample.extras = {"filename": filename, "lineno": lineno} self._sample.status = status self._sample.duration = time.time() - self._sample.start_time if call.excinfo is not None: self._sample.error_msg = call.excinfo.exconly().strip() self._sample.error_trace = "\n".join( traceback.format_tb(call.excinfo.tb)).strip()
def _get_subsamples(self, call, report, item): recording = self._pop_events() sample = Sample() sample.test_case = item.name if item.parent: sample.test_suite = item.parent.name sample.duration = report.duration sample.status = 'PASSED' if report.passed else 'FAILED' if call.excinfo: sample.error_msg = str(call.excinfo.value) sample.error_trace = traceback.format_tb(call.excinfo.tb) extr = ApiritifSampleExtractor() trace = extr.parse_recording(recording, sample) toplevel_sample = trace[0].to_dict() self._filter([toplevel_sample]) return toplevel_sample
def beforeTest(self, test): """ before test run """ addr = test.address( ) # file path, package.subpackage.module, class.method test_file, module_fqn, class_method = addr test_fqn = test.id() # [package].module.class.method suite_name, case_name = test_fqn.split('.')[-2:] log.debug("Addr: %r", addr) log.debug("id: %r", test_fqn) if class_method is None: class_method = case_name self.current_sample = Sample(test_case=case_name, test_suite=suite_name, start_time=time.time(), status="SKIPPED") self.current_sample.extras.update({ "file": test_file, "full_name": test_fqn, "description": test.shortDescription() }) module_fqn_parts = module_fqn.split('.') for item in module_fqn_parts[:-1]: self.current_sample.path.append(PathComponent("package", item)) self.current_sample.path.append( PathComponent("module", module_fqn_parts[-1])) if "." in class_method: # TestClass.test_method class_name, method_name = class_method.split('.')[:2] self.current_sample.path.extend([ PathComponent("class", class_name), PathComponent("method", method_name) ]) else: # test_func self.current_sample.path.append(PathComponent( "func", class_method)) log.debug("Test method path: %r", self.current_sample.path) self.test_count += 1
def end_test(self, name, attrs): # TODO: include keywords as subsamples sample = Sample() sample.test_case = name sample.test_suite = self._current_suite sample.start_time = time.mktime(datetime.strptime(attrs['starttime'], '%Y%m%d %H:%M:%S.%f').timetuple()) sample.duration = attrs['elapsedtime'] / 1000 if attrs['status'] == 'PASS': sample.status = 'PASSED' else: sample.status = 'FAILED' message = attrs['message'] if '\n' in message: lines = message.split('\n') sample.error_msg = lines[0] sample.error_trace = message else: sample.error_msg = message self._report_sample(sample)
def beforeTest(self, test): """ before test run """ test_file, _, _ = test.address( ) # file path, module name, class.method test_fqn = test.id() # [package].module.class.method class_name, method_name = test_fqn.split('.')[-2:] self.current_sample = Sample(test_case=method_name, test_suite=class_name, start_time=time.time(), status="SKIPPED") self.current_sample.extras.update({ "file": test_file, "full_name": test_fqn, "description": test.shortDescription() }) self.test_count += 1