From 2f9aa41614a9d7c98696178598e4969ef0f37d0c Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 5 Jun 2016 11:56:09 -0700 Subject: [PATCH] Clean up SQLite connections in test harness Windows complains that we can't remove the test database file if open connections remain. --- beets/dbcore/db.py | 10 ++++++++++ test/helper.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 3f701be59..d1f91389f 100644 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -733,6 +733,16 @@ class Database(object): self._connections[thread_id] = conn return conn + def _close(self): + """Close the current thread's connection to the underlying + SQLite database. + """ + thread_id = threading.current_thread().ident + with self._shared_map_lock: + if thread_id in self._connections: + self._connections[thread_id].close() + del self._connections[thread_id] + @contextlib.contextmanager def _tx_stack(self): """A context manager providing access to the current thread's diff --git a/test/helper.py b/test/helper.py index c10d8fad2..197a85d78 100644 --- a/test/helper.py +++ b/test/helper.py @@ -188,7 +188,7 @@ class TestHelper(object): self.lib = Library(dbpath, self.libdir) def teardown_beets(self): - del self.lib._connections + self.lib._close() if 'BEETSDIR' in os.environ: del os.environ['BEETSDIR'] self.remove_temp_dir()