Clean up SQLite connections in test harness

Windows complains that we can't remove the test database file if open
connections remain.
This commit is contained in:
Adrian Sampson 2016-06-05 11:56:09 -07:00
parent 42d642f1f6
commit 2f9aa41614
2 changed files with 11 additions and 1 deletions

View file

@ -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

View file

@ -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()