Switch to aiosqlite
This commit is contained in:
parent
18bd2cb664
commit
1f54a6a6ac
21 changed files with 698 additions and 549 deletions
|
@ -2,22 +2,25 @@ from typing import Generator
|
|||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy import orm
|
||||
|
||||
from app.database import Base
|
||||
from app.database import async_engine
|
||||
from app.database import async_session
|
||||
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)
|
||||
|
||||
|
||||
def _get_db_for_testing() -> Generator[orm.Session, None, None]:
|
||||
# try:
|
||||
yield _Session # type: ignore
|
||||
# finally:
|
||||
# session.close()
|
||||
@pytest.fixture
|
||||
async def async_db_session():
|
||||
async with async_session() as session:
|
||||
async with async_engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
yield session
|
||||
async with async_engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -46,6 +49,6 @@ def exclude_fastapi_middleware():
|
|||
|
||||
@pytest.fixture
|
||||
def client(db, exclude_fastapi_middleware) -> Generator:
|
||||
app.dependency_overrides[get_db] = _get_db_for_testing
|
||||
# app.dependency_overrides[get_db] = _get_db_for_testing
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue