[3.14] gh-155423: Make BaseFileTest.tearDown() in test_logging robust (GH-155424) (GH-155443)

serhiy-storchaka <[email protected]> Sun, 09 Aug 2026 13:26:50 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/3d591c91799b2ca9c98ab865f41f2e76668e9d82
commit: 3d591c91799b2ca9c98ab865f41f2e76668e9d82
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-08-09T17:26:40Z
summary:

[3.14] gh-155423: Make BaseFileTest.tearDown() in test_logging robust (GH-155424) (GH-155443)

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 <[email protected]>

files:
M Lib/test/test_logging.py

diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 74b740510f3c791..9c626ace7f55d5a 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -6304,11 +6304,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"

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]