Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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:
            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

            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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
    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()