def pytest_runtest_setup(self, item): if not self._cache.get(item.nodeid): uuid = self._cache.push(item.nodeid) test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now()) self.allure_logger.schedule_test(uuid, test_result) yield uuid = self._cache.get(item.nodeid) test_result = self.allure_logger.get_test(uuid) for fixturedef in _test_fixtures(item): group_uuid = self._cache.get(fixturedef) if not group_uuid: group_uuid = self._cache.push(fixturedef) group = TestResultContainer(uuid=group_uuid) self.allure_logger.start_group(group_uuid, group) self.allure_logger.update_group(group_uuid, children=uuid) params = item.callspec.params if hasattr(item, 'callspec') else {} test_result.name = allure_name(item, params) full_name = allure_full_name(item) test_result.fullName = full_name test_result.historyId = md5(item.nodeid) test_result.testCaseId = md5(full_name) test_result.description = allure_description(item) test_result.descriptionHtml = allure_description_html(item) test_result.parameters.extend( [Parameter(name=name, value=represent(value)) for name, value in params.items()])
def pytest_runtest_protocol(self, item, nextitem): uuid = self._cache.set(item.nodeid) for fixturedef in _test_fixtures(item): group_uuid = self._cache.get(fixturedef) if not group_uuid: group_uuid = self._cache.set(fixturedef) group = TestResultContainer(uuid=group_uuid) self.allure_logger.start_group(group_uuid, group) self.allure_logger.update_group(group_uuid, children=uuid) test_case = TestResult(name=item.name, uuid=uuid) self.allure_logger.schedule_test(uuid, test_case) yield test_case.labels += [ Label(name, value) for name, value in allure_labels(item) ] test_case.links += [ Link(link_type, url, name) for link_type, url, name in allure_links(item) ] test_case.labels += [ Label(LabelType.TAG, value) for value in pytest_markers(item) ] test_case.fullName = allure_full_name(item.nodeid) test_case.historyId = md5(test_case.fullName) test_case.labels.append(Label('package', allure_package(item.nodeid))) uuid = self._cache.pop(item.nodeid) self.allure_logger.close_test(uuid)
def _add_result(self, test, trace=None): uuid = uuid4() test = TestSummaryResult(**test) test_result = allure_TestResult(name=test.test_name, uuid=uuid) # test_result.status = self.allure_status(test.test_status) test_result.status = self.allure_status(test.test_status) test_result.fullName = test_result.name test_result.historyId = md5(test_result.fullName) test_result.statusDetails = StatusDetails(message=test.test_message, trace=trace) self.allure_logger.schedule_test(uuid, test_result) self.allure_logger.attach_data(uuid4(), 'aaa', name="request_result", attachment_type="text/plain", extension="txt") self.allure_logger.attach_data(uuid4(), json.dumps(test.test_dict, cls=ComplexEncoder, indent=4, sort_keys=True, ensure_ascii=False), name="case_dict", attachment_type="application/json", extension="json") self.allure_logger.close_test(uuid)
def pytest_runtest_setup(self, item): if not self._cache.get(item.nodeid): uuid = self._cache.push(item.nodeid) test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now()) self.allure_logger.schedule_test(uuid, test_result) yield uuid = self._cache.get(item.nodeid) test_result = self.allure_logger.get_test(uuid) for fixturedef in _test_fixtures(item): group_uuid = self._cache.get(fixturedef) if not group_uuid: group_uuid = self._cache.push(fixturedef) group = TestResultContainer(uuid=group_uuid) self.allure_logger.start_group(group_uuid, group) self.allure_logger.update_group(group_uuid, children=uuid) params = item.callspec.params if hasattr(item, 'callspec') else {} test_result.name = allure_name(item, params) test_result.description = allure_description(item) test_result.descriptionHtml = allure_description_html(item) test_result.fullName = allure_full_name(item) test_result.historyId = md5(test_result.fullName) test_result.parameters.extend( [Parameter(name=name, value=represent(value)) for name, value in params.items()])
def scenario_history_id(scenario, browser): parts = [scenario.feature.name, scenario.name] if scenario._row: row = scenario._row parts.extend(['{name}={value}'.format(name=name, value=value) for name, value in zip(row.headings, row.cells)]) else: parts.extend([browser]) return md5(*parts)
def startTest(self, event): if self.is_registered(): with self.lifecycle.schedule_test_case() as test_result: test_result.name = name(event) test_result.start = timestamp_millis(event.startTime) test_result.fullName = fullname(event) test_result.testCaseId = md5(test_result.fullName) test_result.historyId = md5(event.test.id()) test_result.labels.extend(labels(event.test)) test_result.labels.append( Label(name=LabelType.HOST, value=self._host)) test_result.labels.append( Label(name=LabelType.THREAD, value=self._thread)) test_result.labels.append( Label(name=LabelType.FRAMEWORK, value='nose2')) test_result.labels.append( Label(name=LabelType.LANGUAGE, value=platform_label())) test_result.parameters = params(event)
def start_new_test(self, name, attributes): uuid = uuid4() self.reporter.get_last_item(TestResultContainer).children.append(uuid) self.stack.append(uuid) test_case = TestResult(uuid=uuid, historyId=md5(attributes.get('longname')), name=name, fullName=attributes.get('longname'), start=now()) self.reporter.schedule_test(uuid, test_case)
def start_test(self, name, attributes): uuid = uuid4() with self.lifecycle.schedule_test_case(uuid=uuid) as test_result: long_name = attributes.get('longname') test_result.name = name test_result.fullName = long_name test_result.historyId = md5(long_name) test_result.start = now() for container in self.lifecycle.containers(): container.children.append(uuid)
def pytest_runtest_protocol(self, item, nextitem): uuid = self._cache.set(item.nodeid) for fixturedef in _test_fixtures(item): group_uuid = self._cache.get(fixturedef) if not group_uuid: group_uuid = self._cache.set(fixturedef) group = TestResultContainer(uuid=group_uuid) self.allure_logger.start_group(group_uuid, group) self.allure_logger.update_group(group_uuid, children=uuid) test_case = TestResult(name=allure_name(item), uuid=uuid) self.allure_logger.schedule_test(uuid, test_case) if hasattr(item, 'function'): test_case.description = item.function.__doc__ yield for name, value in item.callspec.params.items() if hasattr( item, 'callspec') else (): test_result = self.allure_logger.get_test(uuid) if test_result: test_result.parameters.append(Parameter( name, represent(value))) test_case.labels.extend([ Label(name=name, value=value) for name, value in allure_labels(item) ]) test_case.labels.extend([ Label(name=LabelType.TAG, value=value) for value in pytest_markers(item) ]) test_case.labels.append(Label(name=LabelType.HOST, value=self._host)) test_case.labels.append( Label(name=LabelType.THREAD, value=self._thread)) test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='pytest')) test_case.labels.append( Label(name=LabelType.LANGUAGE, value=platform_label())) test_case.links += [ Link(link_type, url, name) for link_type, url, name in allure_links(item) ] test_case.fullName = allure_full_name(item) test_case.historyId = md5(test_case.fullName) test_case.labels.append(Label('package', allure_package(item))) uuid = self._cache.pop(item.nodeid) self.allure_logger.close_test(uuid)
def pytest_bdd_before_scenario(self, request, feature, scenario): uuid = get_uuid(request.node.nodeid) full_name = get_full_name(feature, scenario) name = get_name(request.node, scenario) with self.lifecycle.schedule_test_case(uuid=uuid) as test_result: test_result.fullName = full_name test_result.name = name test_result.start = now() test_result.historyId = md5(request.node.nodeid) test_result.labels.append(Label(name=LabelType.HOST, value=self.host)) test_result.labels.append(Label(name=LabelType.THREAD, value=self.thread)) test_result.labels.append(Label(name=LabelType.FRAMEWORK, value="pytest-bdd")) test_result.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label())) test_result.labels.append(Label(name=LabelType.FEATURE, value=feature.name)) test_result.parameters = get_params(request.node) finalizer = partial(self._scenario_finalizer, scenario) request.node.addfinalizer(finalizer)
def get_uuid(*args): return str(UUID(md5(*args)))
def scenario_history_id(scenario): return md5(scenario.filename, scenario.name)
def scenario_history_id(scenario): parts = [scenario.feature.name, scenario.name] if scenario._row: row = scenario._row parts.extend(['{name}={value}'.format(name=name, value=value) for name, value in zip(row.headings, row.cells)]) return md5(*parts)
def process_test_case(self, test_case, file_modication_datetime=None): with self.lifecycle.schedule_test_case() as test_result: test_index = test_case["id"] test_data = test_case.get("data") or {} job = test_data.get("job") or {} test_result.name = test_index self._record_start_stop(test_result, file_modication_datetime, job) test_result.fullName = test_index test_result.testCaseId = md5(test_index) test_result.historyId = md5(test_index) tool_id = self._record_suite_labels(test_result, test_data, job) self._attach_data("test_data", json.dumps(test_data, indent=JSON_INDENT), attachment_type=AttachmentType.JSON) for key in [ "stderr", "stdout", "command_line", "external_id", "job_messages" ]: val = job.get(key) if not val: continue if isinstance(val, list): attachment_type = AttachmentType.JSON # job messages val = json.dumps(val, indent=JSON_INDENT) else: if not val.strip(): continue attachment_type = AttachmentType.TEXT self._attach_data(key, val, attachment_type=attachment_type) problem_message = None for key in ["execution_problem", "output_problems"]: val = test_data.get(key) if not val: continue if isinstance(val, list) and val: # remove duplicated messages... val = list(set(val)) attachment_type = AttachmentType.HTML as_html_list = "<ul>" as_html_list += "\n".join( [f"<li><pre>{v}</pre></li>" for v in val]) as_html_list += "</ul>" problem_message = val[0] val = as_html_list else: if not val.strip(): continue attachment_type = AttachmentType.TEXT problem_message = val self._attach_data(key, val, attachment_type=attachment_type) if problem_message is None and "job_messages" in job: job_messages = job.get("job_messages") if job_messages: problem_message = str(job_messages) test_result.labels.append( Label(name=LabelType.FRAMEWORK, value='planemo')) test_result.labels.append( Label(name=LabelType.LANGUAGE, value=platform_label())) self._record_tool_link(test_result, tool_id) self._record_status(test_result, test_data) if test_result.status in [Status.BROKEN, Status.FAILED]: test_result.statusDetails = StatusDetails( message=escape_non_unicode_symbols(problem_message or "Unknown problem"), trace=None) self.lifecycle.write_test_case()