[New-bugs-announce] [issue17024] cElementTree calls end() on parser taget even if start() fails

Stefan Behnel report at bugs.python.org
Thu Jan 24 16:10:08 CET 2013

New submission from Stefan Behnel:

The following compatibility unit test fails for me in lxml since Py3.3.

    etree = xml.etree.ElementTree

    def test_parser_target_error_in_start(self):
        assertEqual = self.assertEqual

        events = []
        class Target(object):
            def start(self, tag, attrib):
                assertEqual("TAG", tag)
                raise ValueError("TEST")
            def end(self, tag):
                assertEqual("TAG", tag)
            def close(self):
                return "DONE"

        parser = self.etree.XMLParser(target=Target())

        except ValueError:
            self.assertTrue('TEST' in str(sys.exc_info()[1]))

        # ERROR HERE - gives ["start", "end"] in Py3.3
        self.assertEqual(["start"], events)

It seems like cET doesn't handle exceptions early enough and still calls the end() method. Neither Python ElementTree nor lxml do this.

Some more tests are here:


(all tests in that file are known to work with ET)

components: Library (Lib), XML
messages: 180526
nosy: eli.bendersky, scoder
priority: normal
severity: normal
status: open
title: cElementTree calls end() on parser taget even if start() fails
type: behavior
versions: Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list