Try to fix tests

This commit is contained in:
Thomas Sileo 2022-06-28 23:47:51 +02:00
parent 626a165411
commit f4c70096e2
4 changed files with 38 additions and 11 deletions

View file

@ -8,22 +8,24 @@ from app.database import Base
from app.database import engine
from app.database import get_db
from app.main import app
from tests.factories import _Session
_Session = orm.sessionmaker(bind=engine, autocommit=False, autoflush=False)
# _Session = orm.sessionmaker(bind=engine, autocommit=False, autoflush=False)
def _get_db_for_testing() -> Generator[orm.Session, None, None]:
session = _Session()
try:
yield session
finally:
session.close()
# try:
yield _Session # type: ignore
# finally:
# session.close()
@pytest.fixture
def db() -> Generator:
Base.metadata.create_all(bind=engine)
yield orm.scoped_session(orm.sessionmaker(bind=engine))
# sess = orm.sessionmaker(bind=engine)()
yield _Session
# yield orm.scoped_session(orm.sessionmaker(bind=engine))
try:
Base.metadata.drop_all(bind=engine)
except Exception: