With Python 3.5.1 and nose 1.3.7, xml.etree.ElementTree.ParseError are not handled correctly. For example, with the following test case:
import unittest
try: # python 2
import xml.etree.cElementTree as ET
except ImportError: # python 3, where cElementTree is used by default
import xml.etree.ElementTree as ET
class TestXML(unittest.TestCase):
def test_xml(self):
print('good good')
ET.fromstring('something wrong')
if __name__ == '__main__':
unittest.main()
The following error occurs:
$ python3.5 -m nose test_xml
E
======================================================================
ERROR: test_xml (test_xml.TestXML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/nose/case.py", line 134, in run
self.runTest(result)
File "/usr/lib/python3.5/site-packages/nose/case.py", line 152, in runTest
test(result)
File "/usr/lib/python3.5/unittest/case.py", line 648, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python3.5/unittest/case.py", line 608, in run
self._feedErrorsToResult(result, outcome.errors)
File "/usr/lib/python3.5/unittest/case.py", line 538, in _feedErrorsToResult
result.addError(test, exc_info)
File "/usr/lib/python3.5/site-packages/nose/proxy.py", line 132, in addError
self.result.addError(self.test, self._prepareErr(err))
File "/usr/lib/python3.5/site-packages/nose/result.py", line 61, in addError
exc_info = self._exc_info_to_string(err, test)
File "/usr/lib/python3.5/site-packages/nose/result.py", line 187, in _exc_info_to_string
return _TextTestResult._exc_info_to_string(self, err, test)
File "/usr/lib/python3.5/unittest/result.py", line 186, in _exc_info_to_string
exctype, value, tb, limit=length, capture_locals=self.tb_locals)
File "/usr/lib/python3.5/traceback.py", line 481, in __init__
self.filename = exc_value.filename
AttributeError: 'ParseError' object has no attribute 'filename'
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (errors=1)
Things are OK if:
No print call in the test case:
$ python3.5 -m nose test_xml
E
======================================================================
ERROR: test_xml (test_xml.TestXML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/yen/Executables/Multimedia/youtube-dl/test_xml.py", line 11, in test_xml
ET.fromstring('something wrong')
File "/usr/lib/python3.5/xml/etree/ElementTree.py", line 1320, in XML
parser.feed(text)
File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
Use Python 2.7.11:
$ python2.7 -m nose test_xml
E
======================================================================
ERROR: test_xml (test_xml.TestXML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/yen/Executables/Multimedia/youtube-dl/test_xml.py", line 12, in test_xml
ET.fromstring('something wrong')
File "<string>", line 124, in XML
ParseError: syntax error: line 1, column 0
-------------------- >> begin captured stdout << ---------------------
good good
--------------------- >> end captured stdout << ----------------------
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
Use the built-in unittest runner:
$ python3.5 test_xml.py
good good
E
======================================================================
ERROR: test_xml (__main__.TestXML)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_xml.py", line 12, in test_xml
ET.fromstring('something wrong')
File "/usr/lib/python3.5/xml/etree/ElementTree.py", line 1320, in XML
parser.feed(text)
File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
I'm working on rg3/youtube-dl, and this bug causes lots of false AttributeErrors. For example this Travis CI log.
With Python 3.5.1 and nose 1.3.7,
xml.etree.ElementTree.ParseError
are not handled correctly. For example, with the following test case:The following error occurs:
Things are OK if:
print
call in the test case:I'm working on rg3/youtube-dl, and this bug causes lots of false
AttributeError
s. For example this Travis CI log.