From 2adb6fe246c0e07b30a70cd5c08e4aebc5b2923d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 13 May 2013 22:34:21 +0200 Subject: [PATCH] Fix ResourceWarnings in test_sax --- Lib/test/test_sax.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 502c962d8e0..78a1c697c50 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -574,7 +574,10 @@ class StreamReaderWriterXmlgenTest(XmlgenTest, unittest.TestCase): def ioclass(self): writer = codecs.open(self.fname, 'w', encoding='ascii', errors='xmlcharrefreplace', buffering=0) - self.addCleanup(support.unlink, self.fname) + def cleanup(): + writer.close() + support.unlink(self.fname) + self.addCleanup(cleanup) writer.getvalue = self.getvalue return writer