Exemple #1
0
def pytest_runtest_makereport(item, call):
    when = call.when
    duration = call.stop-call.start
    keywords = dict([(x,1) for x in item.keywords])
    excinfo = call.excinfo
    sections = []
    if not call.excinfo:
        outcome = "passed"
        longrepr = None
    else:
        if not isinstance(excinfo, _code.ExceptionInfo):
            outcome = "failed"
            longrepr = excinfo
        elif excinfo.errisinstance(pytest.skip.Exception):
            outcome = "skipped"
            r = excinfo._getreprcrash()
            longrepr = (str(r.path), r.lineno, r.message)
        else:
            outcome = "failed"
            if call.when == "call" and \
                    isinstance(excinfo.value, AssertionError): #added
                longrepr = item.repr_failure(excinfo)
            else: # exception in setup or teardown
                when = 'setup' if when == 'call' else when  #added
                longrepr = item._repr_failure_py(excinfo,
                                            style=item.config.option.tbstyle)
    for rwhen, key, content in item._report_sections:
        sections.append(("Captured %s %s" %(key, rwhen), content))
    return runner.TestReport(item.nodeid, item.location,
                      keywords, outcome, longrepr, when,
                      sections, duration)
Exemple #2
0
 def report_from_db(self, nodeid):
     node_reports = self.failing_nodes.get(nodeid, {})
     if node_reports:
         for phase in ("setup", "call", "teardown"):
             if phase in node_reports:
                 test_report = runner.TestReport(**node_reports[phase])
                 self.config.hook.pytest_runtest_logreport(report=test_report)
Exemple #3
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))
 def add_failing_reports_from_db(self, failing_stable_nodes):
     """If the nodeid is failed but stable, add it's report instead of running it."""
     for nodeid in failing_stable_nodes:
         # Pass if it wouldn't have been selected without this plugin
         if not (nodeid in self.original_nodeids
                 or home_file(nodeid) in self.original_files):
             continue
         node_report = self.testmon_data.get_report(nodeid)
         if not node_report:
             continue
         for phase in ("setup", "call", "teardown"):
             if phase in node_report:
                 test_report = runner.TestReport(**node_report[phase])
                 self.config.hook.pytest_runtest_logreport(
                     report=test_report)
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))
Exemple #6
0
def forked_run_report(item):
    # for now, we run setup/teardown in the subprocess
    # XXX optionally allow sharing of setup/teardown
    from _pytest.runner import runtestprotocol
    EXITSTATUS_TESTEXIT = 4
    import marshal

    def runforked():
        try:
            reports = runtestprotocol(item, log=False)
        except KeyboardInterrupt:
            os._exit(EXITSTATUS_TESTEXIT)
        return marshal.dumps([serialize_report(x) for x in reports])

    ff = py.process.ForkedFunc(runforked)
    result = ff.waitfinish()
    if result.retval is not None:
        report_dumps = marshal.loads(result.retval)
        return [runner.TestReport(**x) for x in report_dumps]
    else:
        if result.exitstatus == EXITSTATUS_TESTEXIT:
            pytest.exit("forked test item %s raised Exit" % (item, ))
        return [report_process_crash(item, result)]
Exemple #7
0
def unserialize_report(reportdict):
    """
    Generate a :py:class:`TestReport <pytest:_pytest.runner.TestReport>` from a serialized report
    """
    return runner.TestReport(**reportdict)
Exemple #8
0
 def report_if_failed(self, nodeid):
     node_reports = self.testmon_data.fail_reports.get(nodeid, {})
     for phase in ('setup', 'call', 'teardown'):
         if phase in node_reports:
             test_report = runner.TestReport(**node_reports[phase])
             self.config.hook.pytest_runtest_logreport(report=test_report)
Exemple #9
0
def unserialize_report(name, reportdict):
    if name == "testreport":
        return runner.TestReport(**reportdict)
    elif name == "collectreport":
        return runner.CollectReport(**reportdict)
Exemple #10
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))