asyncgenerator fix
This commit is contained in:
@@ -42,7 +42,7 @@ Use migrations to provision an integration database when migrations are part of
|
||||
For tests that exercise code which calls `commit()`, start an outer transaction on one test connection. Bind the test `AsyncSession` to that connection and use `join_transaction_mode="create_savepoint"`. SQLAlchemy documents this as its test-suite pattern: session commits resolve a SAVEPOINT while fixture teardown rolls back the outer transaction.
|
||||
|
||||
```python
|
||||
from collections.abc import AsyncIterator
|
||||
from collections.abc import AsyncGeneratorr
|
||||
|
||||
import pytest_asyncio
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
@@ -50,7 +50,7 @@ from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def session(test_engine: AsyncEngine) -> AsyncIterator[AsyncSession]:
|
||||
async def session(test_engine: AsyncEngine) -> AsyncGenerator[AsyncSession]:
|
||||
async with test_engine.connect() as connection:
|
||||
transaction = await connection.begin()
|
||||
test_session = AsyncSession(
|
||||
@@ -78,7 +78,7 @@ def app_with_test_session(
|
||||
app: FastAPI,
|
||||
session: AsyncSession,
|
||||
) -> FastAPI:
|
||||
async def get_test_session() -> AsyncIterator[AsyncSession]:
|
||||
async def get_test_session() -> AsyncGenerator[AsyncSession]:
|
||||
yield session
|
||||
|
||||
app.dependency_overrides[get_session] = get_test_session
|
||||
@@ -104,7 +104,7 @@ from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def test_engine() -> AsyncIterator[AsyncEngine]:
|
||||
async def test_engine() -> AsyncGenerator[AsyncEngine]:
|
||||
engine, _ = create_database("sqlite+aiosqlite://")
|
||||
async with engine.begin() as connection:
|
||||
await connection.run_sync(SQLModel.metadata.create_all)
|
||||
|
||||
Reference in New Issue
Block a user