From 81dcdfac2bb0b169aeb2a0c4044cf45f41b0ebce Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 9 Aug 2026 19:57:45 +0300 Subject: [PATCH] gh-155423: Make BaseFileTest.tearDown() in test_logging robust (GH-155424) Always call BaseTest.tearDown(), which removes the handlers added by setUp(), even if unlinking the log files fails. Tolerate an already removed file. (cherry picked from commit 6f7fb6c95ba9e4d5c1b86d0d4ad83d0cd495976b) Co-authored-by: Serhiy Storchaka --- Lib/test/test_logging.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 0828aae98dca167..10d2fffc421a1d6 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -6358,11 +6358,12 @@ def setUp(self): self.rmfiles = [] def tearDown(self): - for fn in self.rmfiles: - os.unlink(fn) - if os.path.exists(self.fn): - os.unlink(self.fn) - BaseTest.tearDown(self) + try: + for fn in self.rmfiles: + os_helper.unlink(fn) + os_helper.unlink(self.fn) + finally: + BaseTest.tearDown(self) def assertLogFile(self, filename): "Assert a log file is there and register it for deletion"