Ejemplo n.º 1
0
 def formatTraceback(self, err):
     """Format containing both feature info and traceback info"""
     if isinstance(err, FeatureExcInfo):
         formatted = '\n'.join([err.scenario_name.strip()] + [
             '    ' + completed_step.strip()
             for completed_step in err.completed_steps
         ] + [
             '    ' + err.failed_step.strip(),
             exc_info_to_string(err, super(FeatureTestCase, self))
         ])
         return formatted
     else:
         return exc_info_to_string(err, super(FeatureTestCase, self))
Ejemplo n.º 2
0
 def formatTraceback(self, err):
     """Format containing both feature info and traceback info"""
     if isinstance(err, FeatureExcInfo):
         formatted = '\n'.join([
             err.scenario_name.strip()
         ] + [
             '    ' + completed_step.strip() for completed_step
             in err.completed_steps
         ] + [
             '    ' + err.failed_step.strip(),
             exc_info_to_string(err, super(FeatureTestCase, self))
         ])
         return formatted
     else:
         return exc_info_to_string(err, super(FeatureTestCase, self))
Ejemplo n.º 3
0
    def testOutcome(self, event):
        """Add test outcome to xml tree"""
        test = event.test
        testid_lines = test.id().split('\n')
        testid = testid_lines[0]
        parts = testid.split('.')
        classname = '.'.join(parts[:-1])
        method = parts[-1]
        # for generated test cases
        if len(testid_lines) > 1 and self.test_fullname:
            test_args = ':'.join(testid_lines[1:])
            method = '%s (%s)' % (method, test_args)

        testcase = ET.SubElement(self.tree, 'testcase')
        testcase.set('time', "%.6f" % self._time())
        if not classname:
            classname = test.__module__
        testcase.set('classname', classname)
        testcase.set('name', method)

        msg = ''
        if event.exc_info:
            msg = util.exc_info_to_string(event.exc_info, test)
        elif event.reason:
            msg = event.reason

        msg = string_cleanup(msg, self.keep_restricted)

        if event.outcome == result.ERROR:
            self.errors += 1
            error = ET.SubElement(testcase, 'error')
            error.set('message', 'test failure')
            error.text = msg
        elif event.outcome == result.FAIL and not event.expected:
            self.failed += 1
            failure = ET.SubElement(testcase, 'failure')
            failure.set('message', 'test failure')
            failure.text = msg
        elif event.outcome == result.PASS and not event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'test passes unexpectedly')
        elif event.outcome == result.SKIP:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            if msg:
                skipped.set('message', 'test skipped')
                skipped.text = msg
        elif event.outcome == result.FAIL and event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'expected test failure')
            skipped.text = msg

        system_out = ET.SubElement(testcase, 'system-out')
        system_out.text = string_cleanup(
            '\n'.join(event.metadata.get('logs', '')),
            self.keep_restricted)
Ejemplo n.º 4
0
    def testOutcome(self, event):
        """Add test outcome to xml tree"""
        test = event.test
        testid_lines = test.id().split('\n')
        testid = testid_lines[0]
        parts = testid.split('.')
        classname = '.'.join(parts[:-1])
        method = parts[-1]
        # for generated test cases
        if len(testid_lines) > 1 and self.test_fullname:
            test_args = ':'.join(testid_lines[1:])
            method = '%s (%s)' % (method, test_args)

        testcase = ET.SubElement(self.tree, 'testcase')
        testcase.set('time', "%.6f" % self._time())
        if not classname:
            classname = test.__module__
        testcase.set('classname', classname)
        testcase.set('name', method)

        msg = ''
        if event.exc_info:
            msg = util.exc_info_to_string(event.exc_info, test)
        elif event.reason:
            msg = event.reason

        msg = string_cleanup(msg, self.keep_restricted)

        if event.outcome == result.ERROR:
            self.errors += 1
            error = ET.SubElement(testcase, 'error')
            error.set('message', 'test failure')
            error.text = msg
        elif event.outcome == result.FAIL and not event.expected:
            self.failed += 1
            failure = ET.SubElement(testcase, 'failure')
            failure.set('message', 'test failure')
            failure.text = msg
        elif event.outcome == result.PASS and not event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'test passes unexpectedly')
        elif event.outcome == result.SKIP:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            if msg:
                skipped.set('message', 'test skipped')
                skipped.text = msg
        elif event.outcome == result.FAIL and event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'expected test failure')
            skipped.text = msg

        system_out = ET.SubElement(testcase, 'system-out')
        system_out.text = string_cleanup(
            '\n'.join(event.metadata.get('logs', '')), self.keep_restricted)
Ejemplo n.º 5
0
def status_details(event):
    message, trace = None, None
    if event.exc_info:
        exc_type, value, _ = event.exc_info
        message = '\n'.join(format_exception_only(
            exc_type, value)) if exc_type or value else None
        trace = ''.join(util.exc_info_to_string(event.exc_info, event.test))
    elif event.reason:
        message = event.reason

    if message or trace:
        return StatusDetails(message=message, trace=trace)
Ejemplo n.º 6
0
    def testOutcome(self, event):
        """Plugins can use this hook to take action based on the outcome of tests. Here we add test outcome to xml tree"""
        test = event.test
        testid = test.id().split('\n')[0]
        # split into module, class, method parts... somehow
        parts = testid.split('.')
        classname = '.'.join(parts[:-1])
        method = parts[-1]

        testcase = ET.SubElement(self.tree, 'testcase')
        testcase.set('time', "%.6f" % self._time())
        testcase.set('classname', classname)
        testcase.set('name', method)

        msg = ''
        if event.exc_info:
            msg = util.exc_info_to_string(event.exc_info, test)
        elif event.reason:
            msg = event.reason

        msg = string_cleanup(msg, self.keep_restricted)

        if event.outcome == result.ERROR:
            self.errors += 1
            error = ET.SubElement(testcase, 'error')
            error.set('message', 'test failure')
            error.text = msg
        elif event.outcome == result.FAIL and not event.expected:
            self.failed += 1
            failure = ET.SubElement(testcase, 'failure')
            failure.set('message', 'test failure')
            failure.text = msg
        elif event.outcome == result.PASS and not event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'test passes unexpectedly')
        elif event.outcome == result.SKIP:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set(
                'message',
                msg)  # This is the line we had to add to display skip messages
        elif event.outcome == result.FAIL and event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'expected test failure')
            skipped.text = msg

        system_err = ET.SubElement(testcase, 'system-err')
        system_err.text = string_cleanup(
            '\n'.join(event.metadata.get('logs', '')), self.keep_restricted)
Ejemplo n.º 7
0
Archivo: result.py Proyecto: atdt/nose2
 def _getOutcomeDetail(self, event):
     evt = events.OutcomeDetailEvent(event)
     result = self.session.hooks.outcomeDetail(evt)
     if evt.handled:
         return result
     exc_info = getattr(event, 'exc_info', None)
     test = getattr(event, 'test', None)
     if exc_info:
         detail = [util.exc_info_to_string(exc_info, test)]
     else:
         detail = []
     if evt.extraDetail:
         detail.extend(evt.extraDetail)
     return "\n".join(detail)
Ejemplo n.º 8
0
 def _getOutcomeDetail(self, event):
     evt = events.OutcomeDetailEvent(event)
     result = self.session.hooks.outcomeDetail(evt)
     if evt.handled:
         return result
     exc_info = getattr(event, 'exc_info', None)
     test = getattr(event, 'test', None)
     if exc_info:
         detail = [util.exc_info_to_string(exc_info, test)]
     else:
         detail = []
     if evt.extraDetail:
         detail.extend(evt.extraDetail)
     return "\n".join(detail)
Ejemplo n.º 9
0
    def testOutcome(self, event):
        """Add test outcome to xml tree"""
        test = event.test
        testid = test.id().split('\n')[0]
        # split into module, class, method parts... somehow
        parts = testid.split('.')
        classname = '.'.join(parts[:-1])
        method = parts[-1]

        testcase = ET.SubElement(self.tree, 'testcase')
        testcase.set('time', "%.6f" % self._time())
        testcase.set('classname', classname)
        testcase.set('name', method)

        msg = ''
        if event.exc_info:
            msg = util.exc_info_to_string(event.exc_info, test)
        elif event.reason:
            msg = event.reason

        msg = string_cleanup(msg, self.keep_restricted)

        if event.outcome == result.ERROR:
            self.errors += 1
            error = ET.SubElement(testcase, 'error')
            error.set('message', 'test failure')
            error.text = msg
        elif event.outcome == result.FAIL and not event.expected:
            self.failed += 1
            failure = ET.SubElement(testcase, 'failure')
            failure.set('message', 'test failure')
            failure.text = msg
        elif event.outcome == result.PASS and not event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'test passes unexpectedly')
        elif event.outcome == result.SKIP:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
        elif event.outcome == result.FAIL and event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'expected test failure')
            skipped.text = msg

        system_err = ET.SubElement(testcase, 'system-err')
        system_err.text = string_cleanup(
            '\n'.join(event.metadata.get('logs', '')),
            self.keep_restricted
        )
Ejemplo n.º 10
0
    def testOutcome(self, event):
        """Add test outcome to xml tree"""
        test = event.test
        testid = test.id().split('\n')[0]
        # split into module, class, method parts... somehow
        parts = testid.split('.')
        classname = '.'.join(parts[:-1])
        method = parts[-1]

        testcase = ET.SubElement(self.tree, 'testcase')
        testcase.set('time', "%.6f" % self._time())
        testcase.set('classname', classname)
        testcase.set('name', method)

        msg = ''
        if event.exc_info:
            msg = util.exc_info_to_string(event.exc_info, test)
        elif event.reason:
            msg = event.reason

        msg = string_cleanup(msg, self.keep_restricted)

        if event.outcome == result.ERROR:
            self.errors += 1
            error = ET.SubElement(testcase, 'error')
            error.set('message', 'test failure')
            error.text = msg
        elif event.outcome == result.FAIL and not event.expected:
            self.failed += 1
            failure = ET.SubElement(testcase, 'failure')
            failure.set('message', 'test failure')
            failure.text = msg
        elif event.outcome == result.PASS and not event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'test passes unexpectedly')
        elif event.outcome == result.SKIP:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
        elif event.outcome == result.FAIL and event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, 'skipped')
            skipped.set('message', 'expected test failure')
            skipped.text = msg
Ejemplo n.º 11
0
    def testOutcome(self, event):
        """Add test outcome to xml tree"""
        test = event.test
        testid_lines = test.id().split("\n")
        testid = testid_lines[0]
        parts = testid.split(".")
        classname = ".".join(parts[:-1])
        method = parts[-1]
        # for generated test cases
        if len(testid_lines) > 1 and self.test_fullname:
            test_args = ":".join(testid_lines[1:])
            method = "%s (%s)" % (method, test_args)

        # subtests do not report success
        if event.outcome == result.SUBTEST and event.exc_info is None:
            return

        testcase = ET.SubElement(self.tree, "testcase")
        testcase.set("timestamp", self._iso_timestamp())
        testcase.set("time", "%.6f" % self._time())
        if not classname:
            classname = test.__module__
        testcase.set("classname", classname)
        testcase.set("name", method)

        msg = ""
        if event.exc_info:
            msg = util.exc_info_to_string(event.exc_info, test)
        elif event.reason:
            msg = event.reason

        msg = string_cleanup(msg, self.keep_restricted)

        if event.outcome == result.ERROR:
            self.errors += 1
            error = ET.SubElement(testcase, "error")
            error.set("message", "test failure")
            error.text = msg
        elif event.outcome == result.FAIL and not event.expected:
            self.failed += 1
            failure = ET.SubElement(testcase, "failure")
            failure.set("message", "test failure")
            failure.text = msg
        elif event.outcome == result.PASS and not event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, "skipped")
            skipped.set("message", "test passes unexpectedly")
        elif event.outcome == result.SKIP:
            self.skipped += 1
            skipped = ET.SubElement(testcase, "skipped")
            if msg:
                skipmsg = "test skipped"
                if event.reason:
                    skipmsg = "test skipped: {}".format(event.reason)
                skipped.set("message", skipmsg)
                skipped.text = msg
        elif event.outcome == result.FAIL and event.expected:
            self.skipped += 1
            skipped = ET.SubElement(testcase, "skipped")
            skipped.set("message", "expected test failure")
            skipped.text = msg
        elif event.outcome == result.SUBTEST:
            if issubclass(event.exc_info[0], event.test.failureException):
                self.failed += 1
                failure = ET.SubElement(testcase, "failure")
                failure.set("message", "test failure")
                failure.text = msg
            else:
                self.errors += 1
                error = ET.SubElement(testcase, "error")
                error.set("message", "test failure")
                error.text = msg

        system_out = ET.SubElement(testcase, "system-out")
        system_out.text = string_cleanup(
            "\n".join(event.metadata.get("logs", "")), self.keep_restricted)
Ejemplo n.º 12
0
 def _get_traceback(self, event):
     """ extracts the traceback from the test """
     return util.exc_info_to_string(event.testEvent.exc_info, event.testEvent.test)