This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author arturcz
Recipients arturcz, eric.araujo, loewis, peter.otten, serhiy.storchaka
Date 2014-02-23.20:08:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1393186129.21.0.629445846761.issue20714@psf.upfronthosting.co.za>
In-reply-to
Content
Martin, the exact information you need are:

1. this is what I did:

#!/usr/bin/env python
import unittest
import xmlrunner

class Foo(unittest.TestCase):
    def testFoo(self):
        self.assertTrue(False, ']]>')

unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))

2. this is what happened:
arturcz@szczaw:/tmp$ ./cdata.py 

Running tests...
----------------------------------------------------------------------
F
======================================================================
FAIL [0.000s]: testFoo (__main__.Foo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./cdata.py", line 7, in testFoo
    self.assertTrue(False, ']]>')
AssertionError: ]]>

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)

Generating XML reports...
Traceback (most recent call last):
  File "./cdata.py", line 9, in <module>
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
  File "/usr/lib/python2.7/unittest/main.py", line 95, in __init__
    self.runTests()
  File "/usr/lib/python2.7/unittest/main.py", line 232, in runTests
    self.result = testRunner.run(self.test)
  File "/usr/lib/python2.7/dist-packages/xmlrunner/__init__.py", line 415, in run
    result.generate_reports(self)
  File "/usr/lib/python2.7/dist-packages/xmlrunner/__init__.py", line 312, in generate_reports
    xml_content = doc.toprettyxml(indent='\t')
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 58, in toprettyxml
    self.writexml(writer, "", indent, newl, encoding)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1749, in writexml
    node.writexml(writer, indent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
    node.writexml(writer, indent+addindent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
    node.writexml(writer, indent+addindent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 814, in writexml
    node.writexml(writer, indent+addindent, addindent, newl)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 1150, in writexml
    raise ValueError("']]>' not allowed in a CDATA section")
ValueError: ']]>' not allowed in a CDATA section

and empty directory test-reports has been created.

3. this is what should have happened instead:
arturcz@szczaw:/tmp$ ./cdata.py 

Running tests...
----------------------------------------------------------------------
F
======================================================================
FAIL [0.000s]: testFoo (__main__.Foo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./cdata.py", line 7, in testFoo
    self.assertTrue(False, ']]>')
AssertionError: ]]>

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)

Generating XML reports...

and file test-reports/TEST-Foo-${timestamp}.xml is created with following content:
<?xml version="1.0" ?>
<testsuite errors="0" failures="1" name="Foo-20140223203423" tests="1" time="0.000">
        <testcase classname="Foo" name="testFoo" time="0.000">
                <failure message="]]&gt;" type="AssertionError">
<![CDATA[Traceback (most recent call last):
  File "./cdata.py", line 7, in testFoo
    self.assertTrue(False, ']]]]><![CDATA[>')
AssertionError: ]]]]><![CDATA[>
]]>             </failure>
        </testcase>
        <system-out>
<![CDATA[]]>    </system-out>
        <system-err>
<![CDATA[]]>    </system-err>
</testsuite>

however, on the level of minidom.py module, there is an exact test provided in attached repository.

PS. I removed the patch by purpose - it's wrong and someone could be misleaded by it. The correct solution I propose is in the attached repository.
History
Date User Action Args
2014-02-23 20:08:49arturczsetrecipients: + arturcz, loewis, peter.otten, eric.araujo, serhiy.storchaka
2014-02-23 20:08:49arturczsetmessageid: <1393186129.21.0.629445846761.issue20714@psf.upfronthosting.co.za>
2014-02-23 20:08:49arturczlinkissue20714 messages
2014-02-23 20:08:48arturczcreate