[Python-checkins] bpo-33761: Fix a file leak in test_iterparse in test_xml_etree. (GH-7358)

Miss Islington (bot) webhook-mailer at python.org
Sun Jun 3 15:02:23 EDT 2018


https://github.com/python/cpython/commit/2332fedb8d7037172946520bb1a552c7018261d5
commit: 2332fedb8d7037172946520bb1a552c7018261d5
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-06-03T12:02:20-07:00
summary:

bpo-33761: Fix a file leak in test_iterparse in test_xml_etree. (GH-7358)

(cherry picked from commit 13f51d9eec569e08475390e2a8f49f4afed1ea06)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
M Lib/test/test_xml_etree.py

diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index f2e3f8d8b22b..e11397585d97 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -617,6 +617,7 @@ def test_iterparse(self):
         self.assertEqual(str(cm.exception),
                 'junk after document element: line 1, column 12')
 
+        self.addCleanup(support.unlink, TESTFN)
         with open(TESTFN, "wb") as f:
             f.write(b"<document />junk")
         it = iterparse(TESTFN)
@@ -2849,9 +2850,6 @@ def test_setslice_negative_steps(self):
 
 
 class IOTest(unittest.TestCase):
-    def tearDown(self):
-        support.unlink(TESTFN)
-
     def test_encoding(self):
         # Test encoding issues.
         elem = ET.Element("tag")
@@ -2922,12 +2920,14 @@ def test_encoding(self):
                      "<tag key=\"åöö<>\" />" % enc).encode(enc))
 
     def test_write_to_filename(self):
+        self.addCleanup(support.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         tree.write(TESTFN)
         with open(TESTFN, 'rb') as f:
             self.assertEqual(f.read(), b'''<site />''')
 
     def test_write_to_text_file(self):
+        self.addCleanup(support.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         with open(TESTFN, 'w', encoding='utf-8') as f:
             tree.write(f, encoding='unicode')
@@ -2936,6 +2936,7 @@ def test_write_to_text_file(self):
             self.assertEqual(f.read(), b'''<site />''')
 
     def test_write_to_binary_file(self):
+        self.addCleanup(support.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         with open(TESTFN, 'wb') as f:
             tree.write(f)
@@ -2944,6 +2945,7 @@ def test_write_to_binary_file(self):
             self.assertEqual(f.read(), b'''<site />''')
 
     def test_write_to_binary_file_with_bom(self):
+        self.addCleanup(support.unlink, TESTFN)
         tree = ET.ElementTree(ET.XML('''<site />'''))
         # test BOM writing to buffered file
         with open(TESTFN, 'wb') as f:



More information about the Python-checkins mailing list