recreate DB connection

(cherry picked from commit 5593e28)
This commit is contained in:
Ebag333
2017-03-22 20:38:23 -07:00
parent bccb1d2805
commit da493d07c0
2 changed files with 14 additions and 2 deletions

View File

@@ -4,6 +4,9 @@ import pytest
import os
import sys
from sqlalchemy import MetaData, create_engine
from sqlalchemy.orm import sessionmaker
script_dir = os.path.dirname(os.path.abspath(__file__))
# Add root folder to python paths
sys.path.append(os.path.realpath(os.path.join(script_dir, '..', '..')))
@@ -27,6 +30,17 @@ def DBInMemory():
import eos
import eos.db
# Replace the existing DB connection with our own. For some reason on Linux, it ignores what we set above. :(
if callable('sqlite:///:memory:'):
eos.db.saveddata_engine = create_engine(creator='sqlite:///:memory:', echo=eos.config.debug)
else:
eos.db.saveddata_engine = create_engine('sqlite:///:memory:', echo=eos.config.debug)
eos.db.saveddata_meta = MetaData()
eos.db.saveddata_meta.bind = eos.db.saveddata_engine
eos.db.saveddata_session = sessionmaker(bind=eos.db.saveddata_engine, autoflush=False, expire_on_commit=False)()
eos.db.saveddata_meta.create_all()
# Output debug info to help us troubleshoot Travis
print(eos.db.saveddata_engine)
print(eos.db.gamedata_engine)