From ef53014ec17f4dd3a22475d06e35372262cb8b05 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Thu, 29 Oct 2026 15:17:31 -0700 Subject: [PATCH] fix(tests): close the twin database before the bulk-delete temp dir goes (#510) tearDown removed the temp folder before the test's addCleanup closed twin.db, so Windows refused the delete (WinError 32). Register the folder and main database cleanups in setUp so they run after every cleanup a test adds. --- tests/test_bulk_library_delete.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_bulk_library_delete.py b/tests/test_bulk_library_delete.py index 35b9abe6..0e4bfc08 100644 --- a/tests/test_bulk_library_delete.py +++ b/tests/test_bulk_library_delete.py @@ -64,14 +64,15 @@ def table_dump(db): class LibraryDeleteCase(unittest.TestCase): def setUp(self): self.temp = tempfile.TemporaryDirectory() + # Cleanups run last-in first-out and after every cleanup a test adds, + # so a database a test opens (and closes via addCleanup) is closed + # before the folder goes; Windows cannot delete an open file (#510). + self.addCleanup(self.temp.cleanup) self.root = Path(self.temp.name) self.db = PromptDatabase(str(self.root / "delete.db")) + self.addCleanup(self.db.close_all) self.epoch = self.db.get_library_options()["library_epoch"] - def tearDown(self): - self.db.close_all() - self.temp.cleanup() - def paired(self, positive, negative="blur"): pair = self.db.save_prompt_pair(positive, negative) found = self.db.get_prompt_pair(pair)