diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index f2e3f8d8b22..e11397585d9 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -617,6 +617,7 @@ class ElementTreeTest(unittest.TestCase): 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"junk") it = iterparse(TESTFN) @@ -2849,9 +2850,6 @@ class ElementSlicingTest(unittest.TestCase): 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 @@ class IOTest(unittest.TestCase): "" % enc).encode(enc)) def test_write_to_filename(self): + self.addCleanup(support.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) tree.write(TESTFN) with open(TESTFN, 'rb') as f: self.assertEqual(f.read(), b'''''') def test_write_to_text_file(self): + self.addCleanup(support.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) with open(TESTFN, 'w', encoding='utf-8') as f: tree.write(f, encoding='unicode') @@ -2936,6 +2936,7 @@ class IOTest(unittest.TestCase): self.assertEqual(f.read(), b'''''') def test_write_to_binary_file(self): + self.addCleanup(support.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) with open(TESTFN, 'wb') as f: tree.write(f) @@ -2944,6 +2945,7 @@ class IOTest(unittest.TestCase): self.assertEqual(f.read(), b'''''') def test_write_to_binary_file_with_bom(self): + self.addCleanup(support.unlink, TESTFN) tree = ET.ElementTree(ET.XML('''''')) # test BOM writing to buffered file with open(TESTFN, 'wb') as f: