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))
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)
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))