def get_status_details(exception_type, exception, exception_traceback): if isinstance(exception, pytest.skip.Exception): return StatusDetails(message=exception.msg) elif exception: return StatusDetails(message=format_exception(exception_type, exception), trace=format_traceback(exception_traceback))
def step_status_details(result): if result.exception: return StatusDetails(message=format_exception(type(result.exception), result.exception), trace=format_traceback(result.exc_traceback)) elif result.status == 'undefined': message = '\nYou can implement step definitions for undefined steps with these snippets:\n\n' message += make_undefined_step_snippet(result) return StatusDetails(message=message)
def step_status_details(result): if result.exception: message = u','.join(map(lambda s: u'%s' % s, result.exception.args)) message = u'{name}: {message}'.format(name=result.exception.__class__.__name__, message=message) trace = '\n'.join(traceback.format_tb(result.exc_traceback)).decode('utf-8') if result.exc_traceback else None return StatusDetails(message=message, trace=trace) elif result.status == 'undefined': message = u'\nYou can implement step definitions for undefined steps with these snippets:\n\n' message += make_undefined_step_snippet(result) return StatusDetails(message=message)
def pytest_runtest_makereport(self, item, call): uuid = self._cache.get(item.nodeid) report = (yield).get_result() test_result = self.allure_logger.get_test(uuid) status = get_pytest_report_status(report) status_details = None if call.excinfo: message = escape_non_unicode_symbols(call.excinfo.exconly()) if hasattr(report, 'wasxfail'): reason = report.wasxfail message = ('XFAIL {}'.format(reason) if reason else 'XFAIL') + '\n\n' + message trace = escape_non_unicode_symbols(report.longreprtext) status_details = StatusDetails(message=message, trace=trace) if (status != Status.SKIPPED and not (call.excinfo.errisinstance(AssertionError) or call.excinfo.errisinstance(pytest.fail.Exception))): status = Status.BROKEN if status == Status.PASSED and hasattr(report, 'wasxfail'): reason = report.wasxfail message = 'XPASS {reason}'.format( reason=reason) if reason else 'XPASS' status_details = StatusDetails(message=message) if report.when == 'setup': test_result.status = status test_result.statusDetails = status_details if report.when == 'call': if test_result.status == Status.PASSED: test_result.status = status test_result.statusDetails = status_details if report.when == 'teardown': if status in (Status.FAILED, Status.BROKEN ) and test_result.status == Status.PASSED: test_result.status = status test_result.statusDetails = status_details if self.config.option.attach_capture: if report.caplog: self.attach_data(report.caplog, "log", AttachmentType.TEXT, None) if report.capstdout: self.attach_data(report.capstdout, "stdout", AttachmentType.TEXT, None) if report.capstderr: self.attach_data(report.capstderr, "stderr", AttachmentType.TEXT, None)
def step_status_details(result): if result.exception: # workaround for https://github.com/behave/behave/pull/616 trace = result.exc_traceback if type( result.exc_traceback) == list else format_traceback( result.exc_traceback) return StatusDetails(message=format_exception(type(result.exception), result.exception), trace=trace) elif result.status == 'undefined': message = '\nYou can implement step definitions for undefined steps with these snippets:\n\n' message += make_undefined_step_snippet(result) return StatusDetails(message=message)
def step_status_details(result): if result.exception: message = u','.join(map(str, result.exception.args)) message = u'{name}: {message}'.format( name=result.exception.__class__.__name__, message=message) trace = u'\n'.join(traceback.format_tb( result.exc_traceback)) if result.exc_traceback else None message += '\n\nRerun with:\n python manage.py behave -D ipdb \'%s\'' % str( result.location) return StatusDetails(message=message, trace=trace) elif result.status == 'undefined': message = u'\nYou can implement step definitions for undefined steps with these snippets:\n\n' message += make_undefined_step_snippet(result) return StatusDetails(message=message)
def fixture_status_details(exception, exc_traceback): if exception: message = u','.join(map(str, exception.args)) message = u'{name}: {message}'.format(name=exception.__class__.__name__, message=message) trace = u'\n'.join(traceback.format_tb(exc_traceback)) if exc_traceback else None return StatusDetails(message=message, trace=trace) return None
def stop_after_fixture(self, attributes, messages): self._report_messages(messages) with self.lifecycle.update_after_fixture() as fixture: fixture.status = get_allure_status(attributes.get('status')) fixture.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb) self.lifecycle.stop_after_fixture()
def log_message(self, message): message_item = { 'name': message.get('message'), 'start': now(), 'status': Status.FAILED if message.get('level') in RobotLogLevel.CRITICAL_LEVELS else Status.PASSED, 'stop': now() } level = message.get('level') if self._previous_keyword_failed: self._traceback_message = message.get('message') self._previous_keyword_failed = False if level == RobotLogLevel.FAIL: self._previous_keyword_failed = True self.reporter.get_item( self.stack[-1]).statusDetails = StatusDetails( message=message.get('message')) if not self.items_log.get(self.stack[-1]): self.items_log[self.stack[-1]] = [] self.items_log[self.stack[-1]].append((message_item, level))
def stop_current_test(self, name, attributes): uuid = self.stack.pop() test = self.reporter.get_test(uuid) test.status = utils.get_allure_status(attributes.get('status')) test.labels.extend(utils.get_allure_suites(attributes.get('longname'))) test.labels.extend(allure_tags(attributes)) for label_type in (LabelType.EPIC, LabelType.FEATURE, LabelType.STORY): test.labels.extend(allure_labels(attributes, label_type)) for link_type in (LinkType.ISSUE, LinkType.TEST_CASE, LinkType.LINK): test.links.extend(allure_links(attributes, link_type)) test.labels.append(Label(name=LabelType.THREAD, value=self.pool_id)) test.labels.append(Label(name=LabelType.HOST, value=host_tag())) test.labels.append( Label(name=LabelType.FRAMEWORK, value='robotframework')) test.labels.append( Label(name=LabelType.LANGUAGE, value=platform_label())) test.statusDetails = StatusDetails(message=attributes.get('message'), trace=self.get_traceback_message()) test.description = attributes.get('doc') last_link = list(self.links.values())[-1] if self.links else None if attributes.get(Severity.CRITICAL, 'no') == 'yes': test.labels.append( Label(name=LabelType.SEVERITY, value=Severity.CRITICAL)) if last_link: test.links.append(Link(LinkType.LINK, last_link, 'Link')) test.stop = now() self.reporter.close_test(uuid)
def log_message(self, message): level = message.get('level') if level == RobotLogLevel.FAIL: self.reporter.get_item( self.stack[-1]).statusDetails = StatusDetails( message=message.get('message')) self.append_message_to_last_item_log(message, level)
def pytest_runtest_makereport(self, item, call): report = (yield).get_result() status = reduce( lambda final_status, current_status: final_status or getattr( report, current_status, None), ["failed", "passed", "skipped"]) status_details = StatusDetails( message=call.excinfo.exconly(), trace=report.longreprtext) if call.excinfo else None uuid = get_uuid(report.nodeid) with self.lifecycle.update_test_case(uuid=uuid) as test_result: if test_result and report.when == "setup": test_result.status = status test_result.statusDetails = status_details if report.when == "call" and test_result: if test_result.status not in [Status.PASSED, Status.FAILED]: test_result.status = status test_result.statusDetails = status_details if report.when == "teardown" and test_result: if test_result.status == Status.PASSED and status != Status.PASSED: test_result.status = status test_result.statusDetails = status_details if report.when == 'teardown': self.lifecycle.write_test_case(uuid=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_makereport(self, item, call): report = (yield).get_result() status = get_pytest_report_status(report) status_details = StatusDetails( message=call.excinfo.exconly(), trace=report.longreprtext) if call.excinfo else None uuid = get_uuid(report.nodeid) with self.lifecycle.update_test_case(uuid=uuid) as test_result: if test_result and report.when == "setup": test_result.status = status test_result.statusDetails = status_details if report.when == "call" and test_result: if test_result.status not in [Status.PASSED, Status.FAILED]: test_result.status = status test_result.statusDetails = status_details if report.when == "teardown" and test_result: if test_result.status == Status.PASSED and status != Status.PASSED: test_result.status = status test_result.statusDetails = status_details if report.when == 'teardown': self.lifecycle.write_test_case(uuid=uuid)
def stop_keyword(self, attributes, messages): self._report_messages(messages) with self.lifecycle.update_step() as step: step.status = get_allure_status(attributes.get('status')) step.parameters = get_allure_parameters(attributes.get('args')) step.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb) self.lifecycle.stop_step()
def get_status_details(exception_type, exception, exception_traceback): """define test status details""" if exception: return StatusDetails( message=format_exception(exception_type, exception), trace=format_traceback(exception_traceback), ) return None
def log_message(self, message): level = message.get('level') if self._previous_keyword_failed: self._traceback_message = message.get('message') self._previous_keyword_failed = False if level == RobotLogLevel.FAIL: self._previous_keyword_failed = True self.reporter.get_item(self.stack[-1]).statusDetails = StatusDetails(message=message.get('message')) self.append_message_to_last_item_log(message, level)
def pytest_runtest_makereport(self, item, call): uuid = self._cache.set(item.nodeid) report = (yield).get_result() allure_item = self.allure_logger.get_item(uuid) status = allure_item.status or None status_details = None if call.excinfo and hasattr(call.excinfo.value, 'msg'): status_details = StatusDetails(message=call.excinfo.value.msg) elif hasattr(report, 'wasxfail'): status_details = StatusDetails(message=report.wasxfail) elif report.failed: status_details = StatusDetails(message=call.excinfo.exconly(), trace=report.longreprtext) if report.when == 'setup': if report.passed: status = Status.PASSED if report.failed: status = Status.BROKEN if report.skipped: status = Status.SKIPPED if report.when == 'call': if report.passed and status == Status.PASSED: pass if report.failed: status = Status.FAILED if report.skipped: status = Status.SKIPPED if report.when == 'teardown': if report.failed and status == Status.PASSED: status = Status.BROKEN test_result = self.allure_logger.get_test(uuid) if test_result: if status_details: test_result.status = status test_result.statusDetails = status_details else: test_result.status = status
def pytest_runtest_makereport(self, item, call): uuid = self._cache.set(item.nodeid) report = (yield).get_result() test_result = self.allure_logger.get_test(uuid) status = get_pytest_report_status(report) status_details = None if call.excinfo: status_details = StatusDetails( message=escape_non_unicode_symbols(call.excinfo.exconly()), trace=escape_non_unicode_symbols(report.longreprtext)) if (status != Status.SKIPPED and not (call.excinfo.errisinstance(AssertionError) or call.excinfo.errisinstance(pytest.fail.Exception))): status = Status.BROKEN if status == Status.PASSED and hasattr(report, 'wasxfail'): reason = report.wasxfail message = 'XPASS {reason}'.format( reason=reason) if reason else 'XPASS' status_details = StatusDetails(message=message) if report.when == 'setup': test_result.status = status test_result.statusDetails = status_details if report.when == 'call': if test_result.status == Status.PASSED: test_result.status = status test_result.statusDetails = status_details if report.when == 'teardown': if status in (Status.FAILED, Status.BROKEN ) and test_result.status == Status.PASSED: test_result.status = status test_result.statusDetails = status_details uuid = self._cache.pop(item.nodeid) self.allure_logger.close_test(uuid)
def status_details(event): message, trace = None, None if event.exc_info: exc_type, value, _ = event.exc_info message = '\n'.join(format_exception_only( exc_type, value)) if exc_type or value else None trace = ''.join(util.exc_info_to_string(event.exc_info, event.test)) elif event.reason: message = event.reason if message or trace: return StatusDetails(message=message, trace=trace)
def stop_test_container(self, name, attributes): suite_status = get_allure_status(attributes.get('status')) suite_message = attributes.get('message') with self.lifecycle.schedule_test_case() as test_result: if test_result.status == Status.PASSED and suite_message: test_result.status = suite_status test_result.statusDetails = StatusDetails( message=self._current_msg or suite_message, trace=self._current_tb) self._current_tb, self._current_msg = None, None self.lifecycle.write_container()
def stop_current_test(self, name, attributes): uuid = self.stack.pop() test = self.reporter.get_test(uuid) test.status = utils.get_allure_status(attributes.get('status')) test.labels.extend(utils.get_allure_suites(attributes.get('longname'))) test.labels.extend(utils.get_allure_tags(attributes.get('tags'))) test.labels.append(utils.get_allure_thread(self.pool_id)) test.labels.append(Label(LabelType.HOST, value=host_tag())) test.statusDetails = StatusDetails(message=attributes.get('message')) test.description = attributes.get('doc') last_link = list(self.links.values())[-1] if self.links else None if last_link: test.links.append(Link(LinkType.LINK, last_link, 'Link')) test.stop = now() self.reporter.close_test(uuid)
def testOutcome(self, event): if self.is_registered(): with self.lifecycle.update_test_case() as test_result: if event.outcome == result.PASS and event.expected: test_result.status = Status.PASSED elif event.outcome == result.PASS and not event.expected: test_result.status = Status.PASSED test_result.statusDetails = StatusDetails( message="test passes unexpectedly") elif event.outcome == result.FAIL and not event.expected: test_result.status = Status.FAILED test_result.statusDetails = status_details(event) elif event.outcome == result.ERROR: test_result.status = Status.BROKEN test_result.statusDetails = status_details(event) elif event.outcome == result.SKIP: test_result.status = Status.SKIPPED test_result.statusDetails = status_details(event)
def stop_test(self, _, attributes, messages): self._report_messages(messages) if 'skipped' in [tag.lower() for tag in attributes['tags']]: attributes['status'] = RobotStatus.SKIPPED with self.lifecycle.update_test_case() as test_result: test_result.stop = now() test_result.description = attributes.get('doc') test_result.status = get_allure_status(attributes.get('status')) test_result.labels.extend( get_allure_suites(attributes.get('longname'))) test_result.labels.append( Label(name=LabelType.FRAMEWORK, value='robotframework')) test_result.labels.append( Label(name=LabelType.LANGUAGE, value=self._platform)) test_result.labels.append( Label(name=LabelType.HOST, value=self._host)) test_result.labels.append( Label(name=LabelType.THREAD, value=pool_id())) test_result.labels.extend(allure_tags(attributes)) test_result.statusDetails = StatusDetails( message=self._current_msg or attributes.get('message'), trace=self._current_tb) if attributes.get('critical') == 'yes': test_result.labels.append( Label(name=LabelType.SEVERITY, value=Severity.CRITICAL)) for label_type in (LabelType.EPIC, LabelType.FEATURE, LabelType.STORY): test_result.labels.extend(allure_labels( attributes, label_type)) for link_type in (LinkType.ISSUE, LinkType.TEST_CASE, LinkType.LINK): test_result.links.extend(allure_links(attributes, link_type)) self._current_tb, self._current_msg = None, None
def stop_current_test(self, name, attributes): uuid = self.stack.pop() test = self.reporter.get_test(uuid) test.status = utils.get_allure_status(attributes.get('status')) test.labels.extend(utils.get_allure_suites(attributes.get('longname'))) test.labels.extend(utils.get_allure_tags(attributes.get('tags'))) test.labels.append(utils.get_allure_thread(self.pool_id)) test.labels.append(Label(LabelType.HOST, value=host_tag())) test.labels.append( Label(name=LabelType.FRAMEWORK, value='robotframework')) test.labels.append( Label(name=LabelType.LANGUAGE, value=platform_label())) test.statusDetails = StatusDetails(message=attributes.get('message')) test.description = attributes.get('doc') last_link = list(self.links.values())[-1] if self.links else None if attributes.get(Severity.CRITICAL, 'no') == 'yes': test.labels.append( Label(name=LabelType.SEVERITY, value=Severity.CRITICAL)) if last_link: test.links.append(Link(LinkType.LINK, last_link, 'Link')) test.stop = now() self.reporter.close_test(uuid)
def get_status_details(exception_type, exception, exception_traceback): message = escape_non_unicode_symbols( format_exception(exception_type, exception)) trace = escape_non_unicode_symbols(format_traceback(exception_traceback)) return StatusDetails(message=message, trace=trace) if message or trace else None
def get_status_details(exc_type, exception, exc_traceback): if exception: return StatusDetails(message=format_exception(exc_type, exception), trace=format_traceback(exc_traceback))
def get_status_details(exception): message = str(exception) trace = format_exception(type(exception), exception) return StatusDetails(message=message, trace=trace) if message or trace else None
def get_status_details(exception_type, exception, exception_traceback): message = format_exception(exception_type, exception) trace = format_traceback(exception_traceback) return StatusDetails(message=message, trace=trace) if message or trace else None
def wrapper(self, *args, **kwargs): # pylint: disable=broad-except disable=too-many-branches name = None success = None message = "" traceback_instance = None if callable(title): if title.__doc__: name = title.__doc__ else: name = title.__name__ else: if isinstance(title, str): name = title else: if func.__doc__: name = func.__doc__ else: name = func.__name__ for function, reason in wrapper.disable_functions: if function(self): wrapper.is_disabled = True if reason: wrapper.disable_reasons.append(reason) test_results = [] for test_params in wrapper.parameters: parametrized_testcase_name = resolve_params_in_name( name, test_params) with RtaTestcase(parametrized_testcase_name) as my_testcase: if wrapper.is_disabled: test_result = RtaTestResult( True, parametrized_testcase_name, "test is skipped", None) my_testcase.context.status = Status.SKIPPED if len(wrapper.disable_reasons) > 0: message = "\n".join(wrapper.disable_reasons) my_testcase.context.statusDetails = StatusDetails( message=message) elif kwargs["suite_is_broken"]: test_result = RtaTestResult( False, parametrized_testcase_name, "test suite is broken", None) my_testcase.context.status = Status.BROKEN else: try: self.setup_testcase() print('Running test case "%s"...' % parametrized_testcase_name) func(*args, **test_params) success = True print('Test case "%s" passed!' % parametrized_testcase_name) my_testcase.context.status = Status.PASSED except Exception as ex: success = False print("Test failed!") message = str(ex) traceback_instance = "".join( traceback.TracebackException.from_exception( ex).format()) print(message) print(traceback_instance) try: self.add_crash_data_to_report() except: pass my_testcase.context.status = Status.FAILED my_testcase.context.statusDetails = StatusDetails( message=message, trace=traceback_instance) finally: try: self.teardown_testcase() except: pass test_result = RtaTestResult( success, parametrized_testcase_name, message, traceback_instance) test_results.append(test_result) return test_results