示例#1
0
def pytest_make_collect_report(collector):
    call = runner.CallInfo.from_call(lambda: list(collector.collect()),
                                     'collect')
    longrepr = None
    if not call.excinfo:
        outcome = "passed"
    else:
        from _pytest import nose
        from _pytest.outcomes import Skipped
        skip_exceptions = (Skipped, ) + nose.get_skip_exceptions()
        if call.excinfo.errisinstance(KeyError):
            outcome = "skipped"
            r = collector._repr_failure_py(call.excinfo, "line").reprcrash
            message = "{} not configured in user_opts.py".format(
                r.message.split()[-1])
            longrepr = (str(r.path), r.lineno, message)
        elif call.excinfo.errisinstance(skip_exceptions):
            outcome = "skipped"
            r = collector._repr_failure_py(call.excinfo, "line").reprcrash
            longrepr = (str(r.path), r.lineno, r.message)
        else:
            outcome = "failed"
            errorinfo = collector.repr_failure(call.excinfo)
            if not hasattr(errorinfo, "toterminal"):
                errorinfo = runner.CollectErrorRepr(errorinfo)
            longrepr = errorinfo
    rep = runner.CollectReport(collector.nodeid, outcome, longrepr,
                               getattr(call, 'result', None))
    rep.call = call  # see collect_one_node
    return rep
示例#2
0
def unserialize_report(name, reportdict):
    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

    if name == "testreport":
        return runner.TestReport(**assembled_report(reportdict))
    elif name == "collectreport":
        return runner.CollectReport(**assembled_report(reportdict))
示例#3
0
def unserialize_report(name, reportdict):
    def assembled_report(reportdict):
        from _pytest._code.code import (ReprEntry, ReprExceptionInfo,
                                        ReprFileLocation, ReprFuncArgs,
                                        ReprLocals, ReprTraceback)
        if reportdict['longrepr']:
            if 'reprcrash' and 'reprtraceback' in reportdict['longrepr']:

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

                unserialized_entries = []
                for entry in reprtraceback['reprentries']:
                    reprfuncargs, reprfileloc, reprlocals = None, None, None
                    if entry['reprfuncargs']:
                        reprfuncargs = ReprFuncArgs(**entry['reprfuncargs'])
                    if entry['reprfileloc']:
                        reprfileloc = ReprFileLocation(**entry['reprfileloc'])
                    if entry['reprlocals']:
                        reprlocals = ReprLocals(entry['reprlocals']['lines'])

                    reprentry = ReprEntry(lines=entry['lines'],
                                          reprfuncargs=reprfuncargs,
                                          reprlocals=reprlocals,
                                          filelocrepr=reprfileloc,
                                          style=entry['style'])
                    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

    if name == "testreport":
        return runner.TestReport(**assembled_report(reportdict))
    elif name == "collectreport":
        return runner.CollectReport(**assembled_report(reportdict))
示例#4
0
def unserialize_report(name, reportdict):
    if name == "testreport":
        return runner.TestReport(**reportdict)
    elif name == "collectreport":
        return runner.CollectReport(**reportdict)
示例#5
0
def unserialize_report(name, reportdict):
    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

    if name == "testreport":
        return runner.TestReport(**assembled_report(reportdict))
    elif name == "collectreport":
        return runner.CollectReport(**assembled_report(reportdict))