nose-devs / nose

nose is nicer testing for python
http://readthedocs.org/docs/nose/en/latest/
1.36k stars 396 forks source link

'ParseError' object has no attribute 'filename' #991

Closed yan12125 closed 3 years ago

yan12125 commented 8 years ago

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:

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

yan12125 commented 3 years ago

Closing as nose has been dead for a long time and I see no reason to keep issues open for this project.