mirror of
https://github.com/beetbox/beets.git
synced 2026-02-11 09:54:31 +01:00
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:
parent
42d642f1f6
commit
2f9aa41614
2 changed files with 11 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue