From 659e46611a7da25f9295de922c7b095c9f1601e0 Mon Sep 17 00:00:00 2001 From: spl0k Date: Wed, 29 Aug 2018 18:18:31 +0200 Subject: [PATCH] Fixed tests --- supysonic/db.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/supysonic/db.py b/supysonic/db.py index 88f4574..540bd57 100644 --- a/supysonic/db.py +++ b/supysonic/db.py @@ -540,12 +540,19 @@ def init_database(database_uri): execute_sql_resource_script('schema/migration/{}/{}'.format(settings['provider'], migration)) version.value = SCHEMA_VERSION - metadb.disconnect() - db.bind(**settings) + # Hack for in-memory SQLite databases (used in tests), otherwise 'db' and 'metadb' would be two distinct databases + # and 'db' wouldn't have any table + if settings['provider'] == 'sqlite' and settings['filename'] == ':memory:': + db.provider = metadb.provider + else: + metadb.disconnect() + db.bind(**settings) + db.generate_mapping(check_tables = False) def release_database(): + metadb.disconnect() db.disconnect() - db.provider = None - db.schema = None + db.provider = metadb.provider = None + db.schema = metadb.schema = None