Tweak tests

This commit is contained in:
Thomas Sileo 2022-07-10 15:29:51 +02:00
parent c3c4475e24
commit 229feb23db
2 changed files with 10 additions and 12 deletions

View file

@ -4,13 +4,11 @@ import pytest
from fastapi.testclient import TestClient
from app.database import Base
from app.database import SessionLocal
from app.database import async_engine
from app.database import async_session
from app.database import engine
from app.main import app
from tests.factories import _Session
# _Session = orm.sessionmaker(bind=engine, autocommit=False, autoflush=False)
@pytest.fixture
@ -26,14 +24,14 @@ async def async_db_session():
@pytest.fixture
def db() -> Generator:
Base.metadata.create_all(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:
# XXX: for some reason, the teardown occasionally fails because of this
pass
yield SessionLocal()
finally:
try:
Base.metadata.drop_all(bind=engine)
except Exception:
# XXX: for some reason, the teardown occasionally fails because of this
pass
@pytest.fixture

View file

@ -11,10 +11,10 @@ from app import actor
from app import models
from app.actor import RemoteActor
from app.ap_object import RemoteObject
from app.database import engine
from app.database import SessionLocal
from app.database import now
_Session = orm.scoped_session(orm.sessionmaker(bind=engine))
_Session = orm.scoped_session(SessionLocal)
def generate_key() -> tuple[str, str]: