提交 bfab1c6b 编写于 作者: C Cleber Rosa

xunit plugin: fix DOM usage

On Python 3, it's not possible to create Elements detached from a
Document.  The following code fails (later than it should) on Python
3:

   >>> from xml.dom.minidom import Element
   >>> e = Element('foo')
   >>> e.setAttribute('bar', 'baz')
   Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/lib64/python3.6/xml/dom/minidom.py", line 741, in setAttribute
      attr.ownerDocument = self.ownerDocument
   AttributeError: ownerDocument

Let's create elements within the document, with the `createElement`
API.  According to the docs "The element is not inserted into the
document when it is created", so the (unchanged) code that actually puts
the element in the right place still applies.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 01c84866
......@@ -18,7 +18,7 @@
import datetime
import os
import string
from xml.dom.minidom import Document, Element
from xml.dom.minidom import Document
from avocado.core.parser import FileOrStdoutAction
from avocado.core.output import LOG_UI
......@@ -54,13 +54,13 @@ class XUnitResult(Result):
return testcase
def _create_failure_or_error(self, document, test, element_type):
element = Element(element_type)
element = document.createElement(element_type)
element.setAttribute('type', self._get_attr(test, 'fail_class'))
element.setAttribute('message', self._get_attr(test, 'fail_reason'))
traceback_content = self._escape_cdata(test.get('traceback', self.UNKNOWN))
traceback = document.createCDATASection(traceback_content)
element.appendChild(traceback)
system_out = Element('system-out')
system_out = document.createElement('system-out')
try:
with open(test.get("logfile"), "r") as logfile_obj:
text_output = logfile_obj.read()
......@@ -88,7 +88,7 @@ class XUnitResult(Result):
if status in ('PASS', 'WARN'):
pass
elif status == 'SKIP':
testcase.appendChild(Element('skipped'))
testcase.appendChild(document.createElement('skipped'))
elif status == 'FAIL':
element, system_out = self._create_failure_or_error(document,
test,
......@@ -96,7 +96,7 @@ class XUnitResult(Result):
testcase.appendChild(element)
testcase.appendChild(system_out)
elif status == 'CANCEL':
testcase.appendChild(Element('skipped'))
testcase.appendChild(document.createElement('skipped'))
else:
element, system_out = self._create_failure_or_error(document,
test,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册