From e6c709574049294c510d0441b60f7c1cfd0b6843 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Sun, 25 Oct 2026 08:37:36 -0700 Subject: [PATCH] test(backup): close the old library the close-failure test leaves open CI (py3.12 Linux and the coverage gate) found the old object's executor-thread connections still open at teardown: the test patches its close_all to fail, and once the object is collected close_all_instances no longer reaches it. The test now closes it itself. --- tests/test_restore_review_fixes.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/test_restore_review_fixes.py b/tests/test_restore_review_fixes.py index a5f7014b..f625e307 100644 --- a/tests/test_restore_review_fixes.py +++ b/tests/test_restore_review_fixes.py @@ -70,14 +70,20 @@ class TestPostPublishSteps(RestoreTestCase): self.save("old") old_db = self.api.db body = await self.preview(self.upload(["restored"])) - with patch.object(old_db, "close_all", side_effect=RuntimeError("close")): - started = await self.apply(body["token"]) - job = await self.finish(started["job"]["id"]) - self.assertEqual(job.state, "finished", job.log) - self.assertIsNot(self.api.db, old_db) - self.assertEqual( - [p["text"] for p in self.api.db.search_prompts()], ["restored"] - ) + try: + with patch.object(old_db, "close_all", side_effect=RuntimeError("close")): + started = await self.apply(body["token"]) + job = await self.finish(started["job"]["id"]) + self.assertEqual(job.state, "finished", job.log) + self.assertIsNot(self.api.db, old_db) + self.assertEqual( + [p["text"] for p in self.api.db.search_prompts()], ["restored"] + ) + finally: + # The patched close left the old object's executor-thread + # connections open; close them before teardown removes the files + # (once the object is collected, close_all_instances misses it). + await asyncio.get_running_loop().run_in_executor(None, old_db.close_all) async def test_job_finishes_when_opening_the_new_object_fails(self): self.save("old")