예제 #1
0
    def __init__(self, step, exc):
        self.step = step
        self.exception = exc

        if sys.version_info[:2] < (2, 6):
            msg = exc.message
        else:
            msg = exc.args[0] if exc.args else ''

        if isinstance(msg, str):
            self.cause = utf8_string(msg)
        self.traceback = utf8_string(traceback.format_exc(exc))
예제 #2
0
    def create_test_case_step(step):
        parent = step.scenario or step.background
        if getattr(parent, 'outlines', None):
            return
        
        name = getattr(parent, 'name', 'Background')    # Background sections are nameless

        classname = utf8_string('.'.join([parent.feature.name, name]))
        tc = doc.createElement("testcase")
        tc.setAttribute("classname", classname)
        tc.setAttribute("name", step.sentence.encode('utf-8'))
        try:
            tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))
        except AttributeError:
            tc.setAttribute("time", str(total_seconds(timedelta(seconds=0))))

        if not step.ran:
            skip = doc.createElement("skipped")
            skip.setAttribute("type", "UndefinedStep(%s)" % step.sentence)
            tc.appendChild(skip)

        if step.failed:
            cdata = doc.createCDATASection(step.why.traceback.encode('utf-8'))
            failure = doc.createElement("failure")
            if hasattr(step.why, 'cause'):
                failure.setAttribute("message", step.why.cause.encode('utf-8'))
            failure.setAttribute("type", step.why.exception.__class__.__name__.encode('utf-8'))
            failure.appendChild(cdata)
            tc.appendChild(failure)

        root.appendChild(tc)
    def create_test_case_step(step):
        if step.scenario.outlines:
            return

        classname = utf8_string(u"%s : %s" % (step.scenario.feature.name, step.scenario.name))
        tc = doc.createElement("testcase")
        tc.setAttribute("classname", classname)
        tc.setAttribute("name", step.sentence.encode('utf-8'))
        try:
            tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))
        except AttributeError:
            tc.setAttribute("time", str(total_seconds(timedelta(seconds=0))))

        if not step.ran:
            skip = doc.createElement("skipped")
            skip.setAttribute("type", "UndefinedStep(%s)" % step.sentence)
            tc.appendChild(skip)

        if step.failed:
            cdata = doc.createCDATASection(step.why.traceback.encode('utf-8'))
            failure = doc.createElement("failure")
            if hasattr(step.why, 'cause'):
                failure.setAttribute("message", step.why.cause.encode('utf-8'))
            failure.setAttribute("type", step.why.exception.__class__.__name__.encode('utf-8'))
            failure.appendChild(cdata)
            tc.appendChild(failure)

        root.appendChild(tc)
예제 #4
0
파일: exceptions.py 프로젝트: svfat/lettuce
 def __init__(self, step, exc):
     self.step = step
     self.exception = exc
     if isinstance(exc.message, basestring):
         self.cause = utf8_string(exc.message)
     self.traceback = utf8_string(traceback.format_exc(exc))