unwind/tests/conftest.py
ducklet 4981de4a04 remove databases, use SQLAlechemy 2.0 instead
Among the many changes we switch to using SQLAlchemy's connection pool,
which means we are no longer required to guard against multiple threads
working on the database.
All db funcs now receive a connection to use as their first argument,
this allows the caller to control transaction & rollback behavior.
2023-11-27 23:24:35 +01:00

35 lines
862 B
Python

import asyncio
import pytest
import pytest_asyncio
from unwind import db
@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.new_event_loop()
yield loop
loop.run_until_complete(loop.shutdown_asyncgens())
loop.run_until_complete(loop.shutdown_default_executor())
loop.close()
@pytest_asyncio.fixture(scope="session")
async def shared_conn():
"""A database connection, ready to use."""
await db.open_connection_pool()
async with db.new_connection() as c:
db._test_connection = c
yield c
db._test_connection = None
await db.close_connection_pool()
@pytest_asyncio.fixture
async def conn(shared_conn: db.Connection):
"""A transacted database connection, will be rolled back after use."""
async with db.transacted(shared_conn, force_rollback=True):
yield shared_conn