예제 #1
0
    def _process_data(self, data: Element) -> List[TestGroupReport]:
        """
        XML output contains entries for skipped testcases
        as well, which are not included in the report.
        """
        result = []

        for suite in data.getchildren():
            suite_name = suite.attrib["name"]
            suite_report = TestGroupReport(
                name=suite_name,
                uid=suite_name,
                category=ReportCategories.TESTSUITE,
            )

            for testcase in suite.getchildren():
                if testcase.tag != "testcase":
                    continue

                testcase_classname = testcase.attrib["classname"]
                testcase_name = testcase.attrib["name"]
                testcase_prefix = testcase_classname.split(".")[-1]
                testcase_report = TestCaseReport(
                    name="{}::{}".format(testcase_prefix, testcase_name),
                    uid="{}::{}".format(testcase_classname.replace(".", "::"),
                                        testcase_name),
                )

                if not testcase.getchildren():
                    assertion_obj = RawAssertion(
                        description="Passed",
                        content="Testcase {} passed".format(testcase_name),
                        passed=True,
                    )
                    testcase_report.append(registry.serialize(assertion_obj))
                else:
                    for entry in testcase.getchildren():
                        assertion_obj = RawAssertion(
                            description=entry.tag,
                            content=entry.text,
                            passed=entry.tag not in ("failure", "error"),
                        )
                        testcase_report.append(
                            registry.serialize(assertion_obj))

                testcase_report.runtime_status = RuntimeStatus.FINISHED
                suite_report.append(testcase_report)

            if len(suite_report) > 0:
                result.append(suite_report)

        return result
예제 #2
0
    def _process_data(self, data: Element) -> List[TestGroupReport]:
        """
        Processes data read from the source file.

        :param data: raw data as read by the importer
        """
        # NOTE: XML output contains skipped testcases which are ignored.
        result = []

        for suite in data.getchildren():
            suite_name = suite.attrib["name"]
            suite_report = TestGroupReport(
                name=suite_name,
                category=ReportCategories.TESTSUITE,
            )

            for testcase in suite.getchildren():
                if testcase.tag != "testcase":
                    continue

                testcase_classname = testcase.attrib["classname"]
                testcase_name = testcase.attrib["name"]
                testcase_prefix = testcase_classname.split(".")[-1]
                testcase_report = TestCaseReport(name="{}::{}".format(
                    testcase_prefix, testcase_name), )

                if not testcase.getchildren():
                    assertion_obj = RawAssertion(
                        description="Passed",
                        content=f"Testcase {testcase_name} passed",
                        passed=True,
                    )
                    testcase_report.append(registry.serialize(assertion_obj))
                else:
                    for entry in testcase.getchildren():
                        assertion_obj = RawAssertion(
                            description=entry.tag,
                            content=entry.text,
                            passed=entry.tag not in ("failure", "error"),
                        )
                        testcase_report.append(
                            registry.serialize(assertion_obj))

                testcase_report.runtime_status = RuntimeStatus.FINISHED
                suite_report.append(testcase_report)

            if len(suite_report) > 0:
                result.append(suite_report)

        return result
예제 #3
0
    def _process_data(self, data: Element) -> List[TestGroupReport]:
        """
        Processes data read from the source file.

        :param data: raw data as read by the importer
        """
        result = []

        suites = data.getchildren() if data.tag == "testsuites" else [data]

        for suite in suites:
            suite_name = suite.attrib.get("name")
            suite_report = TestGroupReport(
                name=suite_name,
                category=ReportCategories.TESTSUITE,
            )

            for element in suite.getchildren():
                # Elements like properties, system-out, and system-err are
                # skipped.
                if element.tag != "testcase":
                    continue

                case_class = element.attrib.get("classname")
                case_name = element.attrib.get("name")

                if case_class is None:
                    if case_name == suite_report.name:
                        path = os.path.normpath(case_name)
                        suite_report.name = path.rpartition(os.sep)[-1]
                        # We use the name "Execution" to avoid collision of
                        # test suite and test case.
                        case_report_name = "Execution"
                    else:
                        case_report_name = case_name
                else:
                    case_report_name = (
                        f"{case_class.split('.')[-1]}::{case_name}")

                case_report = TestCaseReport(name=case_report_name)

                if not element.getchildren():
                    assertion = RawAssertion(
                        description="Passed",
                        content=f"Testcase {case_name} passed",
                        passed=True,
                    )
                    case_report.append(registry.serialize(assertion))
                else:
                    # Upon a failure, there will be a single testcase which is
                    # the first child.
                    content, tag, desc = "", None, None
                    for child in element.getchildren():
                        tag = tag or child.tag
                        msg = child.attrib.get("message") or child.text
                        # Approach: if it is a failure/error child, then use
                        # the message attribute directly.
                        # Otherwise, for instance if it is a system-err/out,
                        # then build up the content step by step from it.
                        if not desc and child.tag in ("failure", "error"):
                            desc = msg
                        else:
                            content += f"[{child.tag}]\n{msg}\n"
                    assertion = RawAssertion(
                        description=desc,
                        content=content,
                        passed=tag not in ("failure", "error"),
                    )
                    case_report.append(registry.serialize(assertion))

                suite_report.runtime_status = RuntimeStatus.FINISHED
                suite_report.append(case_report)

            if len(suite_report):
                result.append(suite_report)

        return result