mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-43292: Fix file leak in ET.iterparse()
when not exhausted (GH-31696)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
b748a36696
commit
496c428de3
4 changed files with 20 additions and 7 deletions
|
@ -658,6 +658,14 @@ class ElementTreeTest(unittest.TestCase):
|
|||
'junk after document element: line 1, column 12')
|
||||
del cm, it
|
||||
|
||||
# Not exhausting the iterator still closes the resource (bpo-43292)
|
||||
with warnings_helper.check_no_resource_warning(self):
|
||||
it = iterparse(TESTFN)
|
||||
del it
|
||||
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
iterparse("nonexistent")
|
||||
|
||||
def test_writefile(self):
|
||||
elem = ET.Element("tag")
|
||||
elem.text = "text"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue