lundi 23 septembre 2019

Sqlalchemy - override database engine in tests

I have the foolowing sqlalchmey initialization in my appliation

from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.ext.declarative import declarative_base

engine = create_engine(config.DATABASE_URL, echo=True)
db_session = scoped_session(sessionmaker(bind=engine))


Base = declarative_base()
Base.query = db_session.query_property()

I would like to override the database engine in tests (pytest) to sqlite(in memory)

is it possible to do this per test ?

My goal is that each test case should start with empty(in-meomry-sqlite) database

Aucun commentaire:

Enregistrer un commentaire