コード例 #1
0
    def deserialize_repr_entry(entry_data):
        data = entry_data["data"]
        entry_type = entry_data["type"]
        if entry_type == "ReprEntry":
            reprfuncargs = None
            reprfileloc = None
            reprlocals = None
            if data["reprfuncargs"]:
                reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
            if data["reprfileloc"]:
                reprfileloc = ReprFileLocation(**data["reprfileloc"])
            if data["reprlocals"]:
                reprlocals = ReprLocals(data["reprlocals"]["lines"])

            reprentry: Union[ReprEntry, ReprEntryNative] = ReprEntry(
                lines=data["lines"],
                reprfuncargs=reprfuncargs,
                reprlocals=reprlocals,
                reprfileloc=reprfileloc,
                style=data["style"],
            )
        elif entry_type == "ReprEntryNative":
            reprentry = ReprEntryNative(data["lines"])
        else:
            _report_unserialization_failure(entry_type, TestReport, reportdict)
        return reprentry
コード例 #2
0
    def assembled_report(reportdict):
        from _pytest._code.code import (
            ReprEntry,
            ReprEntryNative,
            ReprExceptionInfo,
            ReprFileLocation,
            ReprFuncArgs,
            ReprLocals,
            ReprTraceback,
        )

        if reportdict["longrepr"]:
            if ("reprcrash" in reportdict["longrepr"]
                    and "reprtraceback" in reportdict["longrepr"]):

                reprtraceback = reportdict["longrepr"]["reprtraceback"]
                reprcrash = reportdict["longrepr"]["reprcrash"]

                unserialized_entries = []
                reprentry = None
                for entry_data in reprtraceback["reprentries"]:
                    data = entry_data["data"]
                    entry_type = entry_data["type"]
                    if entry_type == "ReprEntry":
                        reprfuncargs = None
                        reprfileloc = None
                        reprlocals = None
                        if data["reprfuncargs"]:
                            reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
                        if data["reprfileloc"]:
                            reprfileloc = ReprFileLocation(
                                **data["reprfileloc"])
                        if data["reprlocals"]:
                            reprlocals = ReprLocals(
                                data["reprlocals"]["lines"])

                        reprentry = ReprEntry(
                            lines=data["lines"],
                            reprfuncargs=reprfuncargs,
                            reprlocals=reprlocals,
                            filelocrepr=reprfileloc,
                            style=data["style"],
                        )
                    elif entry_type == "ReprEntryNative":
                        reprentry = ReprEntryNative(data["lines"])
                    else:
                        report_unserialization_failure(entry_type, name,
                                                       reportdict)
                    unserialized_entries.append(reprentry)
                reprtraceback["reprentries"] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict["longrepr"]["sections"]:
                    exception_info.addsection(*section)
                reportdict["longrepr"] = exception_info
        return reportdict
コード例 #3
0
ファイル: reports.py プロジェクト: lauraL123456/xinwumeng
    def _from_json(cls, reportdict):
        """
        This was originally the serialize_report() function from xdist (ca03269).

        Factory method that returns either a TestReport or CollectReport, depending on the calling
        class. It's the callers responsibility to know which class to pass here.

        Experimental method.
        """
        if reportdict["longrepr"]:
            if ("reprcrash" in reportdict["longrepr"]
                    and "reprtraceback" in reportdict["longrepr"]):

                reprtraceback = reportdict["longrepr"]["reprtraceback"]
                reprcrash = reportdict["longrepr"]["reprcrash"]

                unserialized_entries = []
                reprentry = None
                for entry_data in reprtraceback["reprentries"]:
                    data = entry_data["data"]
                    entry_type = entry_data["type"]
                    if entry_type == "ReprEntry":
                        reprfuncargs = None
                        reprfileloc = None
                        reprlocals = None
                        if data["reprfuncargs"]:
                            reprfuncargs = ReprFuncArgs(**data["reprfuncargs"])
                        if data["reprfileloc"]:
                            reprfileloc = ReprFileLocation(
                                **data["reprfileloc"])
                        if data["reprlocals"]:
                            reprlocals = ReprLocals(
                                data["reprlocals"]["lines"])

                        reprentry = ReprEntry(
                            lines=data["lines"],
                            reprfuncargs=reprfuncargs,
                            reprlocals=reprlocals,
                            filelocrepr=reprfileloc,
                            style=data["style"],
                        )
                    elif entry_type == "ReprEntryNative":
                        reprentry = ReprEntryNative(data["lines"])
                    else:
                        _report_unserialization_failure(
                            entry_type, cls, reportdict)
                    unserialized_entries.append(reprentry)
                reprtraceback["reprentries"] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict["longrepr"]["sections"]:
                    exception_info.addsection(*section)
                reportdict["longrepr"] = exception_info

        return cls(**reportdict)
コード例 #4
0
    def assembled_report(reportdict):
        from _pytest._code.code import (
            ReprEntry,
            ReprEntryNative,
            ReprExceptionInfo,
            ReprFileLocation,
            ReprFuncArgs,
            ReprLocals,
            ReprTraceback
        )
        if reportdict['longrepr']:
            if 'reprcrash' in reportdict['longrepr'] and 'reprtraceback' in reportdict['longrepr']:

                reprtraceback = reportdict['longrepr']['reprtraceback']
                reprcrash = reportdict['longrepr']['reprcrash']

                unserialized_entries = []
                reprentry = None
                for entry_data in reprtraceback['reprentries']:
                    data = entry_data['data']
                    entry_type = entry_data['type']
                    if entry_type == 'ReprEntry':
                        reprfuncargs = None
                        reprfileloc = None
                        reprlocals = None
                        if data['reprfuncargs']:
                            reprfuncargs = ReprFuncArgs(
                                **data['reprfuncargs'])
                        if data['reprfileloc']:
                            reprfileloc = ReprFileLocation(
                                **data['reprfileloc'])
                        if data['reprlocals']:
                            reprlocals = ReprLocals(
                                data['reprlocals']['lines'])

                        reprentry = ReprEntry(
                            lines=data['lines'],
                            reprfuncargs=reprfuncargs,
                            reprlocals=reprlocals,
                            filelocrepr=reprfileloc,
                            style=data['style']
                        )
                    elif entry_type == 'ReprEntryNative':
                        reprentry = ReprEntryNative(data['lines'])
                    else:
                        report_unserialization_failure(
                            entry_type, name, reportdict)
                    unserialized_entries.append(reprentry)
                reprtraceback['reprentries'] = unserialized_entries

                exception_info = ReprExceptionInfo(
                    reprtraceback=ReprTraceback(**reprtraceback),
                    reprcrash=ReprFileLocation(**reprcrash),
                )

                for section in reportdict['longrepr']['sections']:
                    exception_info.addsection(*section)
                reportdict['longrepr'] = exception_info
        return reportdict
コード例 #5
0
    def gather_report(self):
        """
    """
        assert (self.post_done == True)

        # -----------------------------------------------------------------
        for nodeid, report_list in self.mpi_reports.items():
            # print("nodeid::", nodeid)

            assert (len(report_list) > 0)

            # > Initialize with the first reporter
            i_rank_report_init, report_init = report_list[0]

            greport = TestReport(
                nodeid,
                report_init.location,
                report_init.keywords,
                report_init.outcome,
                report_init.longrepr,  # longrepr
                report_init.when)

            # print("report_init.location::", report_init.location)
            # print("report_init.longrepr::", type(report_init.longrepr), report_init.longrepr)

            collect_longrepr = []
            # > We need to rebuild a TestReport object, location can be false
            # > Report appears in rank increasing order
            if greport.outcome != 'skipped':
                # Skipped test are only know by proc 0 -> no merge required
                for i_rank_report, test_report in report_list:

                    if (test_report.outcome == 'failed'):
                        greport.outcome = test_report.outcome

                    if (test_report.longrepr):
                        fake_trace_back = ReprTraceback([
                            ReprEntryNative(
                                f"\n\n----------------------- On rank [{test_report._i_rank}/{test_report._n_rank}] / Global [{i_rank_report}/{self.comm.Get_size()}] ----------------------- \n\n"
                            )
                        ], None, None)
                        collect_longrepr.append(
                            (fake_trace_back,
                             ReprFileLocation(*report_init.location), None))
                        collect_longrepr.append(
                            (test_report.longrepr,
                             ReprFileLocation(*report_init.location), None))

                if (len(collect_longrepr) > 0):
                    greport.longrepr = ExceptionChainRepr(collect_longrepr)

            self.reports_gather[nodeid] = [greport]
コード例 #6
0
ファイル: rules.py プロジェクト: burato42/allure-pytest
    def value(self, name, what):
        from _pytest._code.code import (ReprEntry, ReprEntryNative,
                                        ReprExceptionInfo, ReprFileLocation,
                                        ReprFuncArgs, ReprLocals,
                                        ReprTraceback)
        if not isinstance(what, str):
            unserialized_entries = []
            reprentry = None
            for entry_data in what.reprtraceback.reprentries:
                data = entry_data['data']
                entry_type = entry_data['type']
                if entry_type == 'ReprEntry':
                    reprfuncargs = None
                    reprfileloc = None
                    reprlocals = None
                    if data['reprfuncargs']:
                        reprfuncargs = ReprFuncArgs(**data['reprfuncargs'])
                    if data['reprfileloc']:
                        reprfileloc = ReprFileLocation(**data['reprfileloc'])
                    if data['reprlocals']:
                        reprlocals = ReprLocals(data['reprlocals']['lines'])

                    reprentry = ReprEntry(lines=data['lines'],
                                          reprfuncargs=reprfuncargs,
                                          reprlocals=reprlocals,
                                          filelocrepr=reprfileloc,
                                          style=data['style'])
                elif entry_type == 'ReprEntryNative':
                    reprentry = ReprEntryNative(data['lines'])
                else:
                    report_unserialization_failure(entry_type, name,
                                                   reportdict)
                unserialized_entries.append(reprentry)

            what.reprtraceback.reprentries = unserialized_entries
        return element_maker(self.name or name,
                             self.namespace)(legalize_xml(unicodify(what)))