I have the following code that creates an xml doc
self.errorlist.append(
'<testcase classname=%(cls)s name=%(name)s time="%(taken)d">'
'<%(type)s type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]>'
'</%(type)s></testcase>' %
{'cls': self._quoteattr('.'.join(id.split('.')[:-1])),
'name': self._quoteattr(id.split('.')[-1]),
'taken': taken,
'type': type,
'errtype': self._quoteattr(nice_classname(err[0])),
'message': self._quoteattr(exc_message(err)),
'tb': escape_cdata(tb),
})
How can i add a new tag, or new type e.g. “db”
I tried
self.errorlist.append(
'<testcase classname=%(cls)s name=%(name)s db=%(db)s time="%(taken)d">'
'<%(type)s type=%(errtype)s message=%(message)s><![CDATA[%(tb)s]]>'
'</%(type)s></testcase>' %
{'cls': self._quoteattr('.'.join(id.split('.')[:-1])),
'name': self._quoteattr(id.split('.')[-1]),
'taken': taken,
'type': type,
'errtype': self._quoteattr(nice_classname(err[0])),
'message': self._quoteattr(exc_message(err)),
'tb': escape_cdata(tb),
})
but got : KeyError: ‘db’
i also tried just plain %(db)s but got error:
NameError: global name ‘db’ is not defined
Following is the import
from xml.sax import saxutils
solved: using the code below, i was abe to get db=”mysql” in the XML Doc