33from __future__ import annotations
44
55import json
6+ from collections .abc import Generator
67from pathlib import Path
78
89import pytest
@@ -55,9 +56,10 @@ class TestLogAction:
5556 """Tests for MemoryStore.log_action()."""
5657
5758 @pytest .fixture ()
58- def store (self , tmp_path : Path ) -> MemoryStore :
59- """Return a fresh MemoryStore backed by a temp-file DB."""
60- return MemoryStore (tmp_path / "memory.db" )
59+ def store (self , tmp_path : Path ) -> Generator [MemoryStore , None , None ]:
60+ """Return a fresh MemoryStore backed by a temp-file DB, closed after the test."""
61+ with MemoryStore (tmp_path / "memory.db" ) as s :
62+ yield s
6163
6264 def test_log_action_inserts_row (self , store : MemoryStore ) -> None :
6365 """log_action writes a record to action_log."""
@@ -71,7 +73,6 @@ def test_log_action_inserts_row(self, store: MemoryStore) -> None:
7173 rationale = "Matches bug pattern." ,
7274 actions = [ActionItem (type = "add_label" , label = "bug" )],
7375 )
74- store .close ()
7576
7677 with sqlite3 .connect (store .db_path ) as conn :
7778 rows = conn .execute ("SELECT * FROM action_log" ).fetchall ()
@@ -90,7 +91,6 @@ def test_log_action_stores_correct_values(self, store: MemoryStore) -> None:
9091 rationale = "Looks like a bug." ,
9192 actions = actions ,
9293 )
93- store .close ()
9494
9595 with sqlite3 .connect (store .db_path ) as conn :
9696 row = conn .execute (
@@ -119,7 +119,6 @@ def test_log_action_multiple_entries(self, store: MemoryStore) -> None:
119119 rationale = "No action." ,
120120 actions = [],
121121 )
122- store .close ()
123122
124123 with sqlite3 .connect (store .db_path ) as conn :
125124 count = conn .execute ("SELECT COUNT(*) FROM action_log" ).fetchone ()[0 ]
@@ -137,7 +136,6 @@ def test_log_action_null_rationale(self, store: MemoryStore) -> None:
137136 rationale = None ,
138137 actions = [],
139138 )
140- store .close ()
141139
142140 with sqlite3 .connect (store .db_path ) as conn :
143141 row = conn .execute ("SELECT rationale FROM action_log" ).fetchone ()
@@ -148,9 +146,10 @@ class TestMemorySummary:
148146 """Tests for MemoryStore.get_memory_summary() and upsert_memory_summary()."""
149147
150148 @pytest .fixture ()
151- def store (self , tmp_path : Path ) -> MemoryStore :
152- """Return a fresh MemoryStore backed by a temp-file DB."""
153- return MemoryStore (tmp_path / "memory.db" )
149+ def store (self , tmp_path : Path ) -> Generator [MemoryStore , None , None ]:
150+ """Return a fresh MemoryStore backed by a temp-file DB, closed after the test."""
151+ with MemoryStore (tmp_path / "memory.db" ) as s :
152+ yield s
154153
155154 def test_get_summary_returns_none_when_absent (self , store : MemoryStore ) -> None :
156155 """get_memory_summary returns None when no summary exists for the issue."""
0 commit comments