python - Use Alembic to upgrade in-memory sqlite3 database -
i have flask app created app factory. when testing pytest, want use in-memory sqlite database because faster using temporary files. i'm using flask-migrate integrate alembic , flask-sqlalchemy. flask-migrate uses command line commands manage database. how can run migrations set database within test code?
config.py
:
class defaultconfig(object): debug = true testing = true csrf_enabled = true secret_key = 'this-really-needs-to-change' sqlalchemy_database_uri = 'sqlite://'
__init__.py
:
db = sqlalchemy() socketio = socketio() migrate = migrate() def create_app(config=none): app = flask(__name__) if config not none: config_path = os.path.abspath(config) app.config.from_pyfile(config_path) elif os.path.isfile(os.path.abspath(configfile)): app.config.from_pyfile(os.path.abspath(configfile)) else: app.config.from_object(defaultconfig) db.init_app(app) socketio.init_app(app) migrate.init_app(app, db) return app
fixtures.py
:
from flask.ext.migrate import upgrade . import create_app, db .models import user class appfixture(object): def __init__(self): self.app = create_app() self.db = db self.app.app_context(): upgrade() self.users = user.query.all()
calling upgrade()
above doesn't work, operationalerror: (sqlite3.operationalerror) no such table: user [sql: u'select...
@ users.query
line afterwards.
not enough rep leave comment, i'm writing answer: there seems issue using flask upgrade
in sqllite in-memory dbs.
Comments
Post a Comment