2021-12-19 19:30:08 +01:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
import pytest
|
2023-02-04 18:12:50 +01:00
|
|
|
import pytest_asyncio
|
|
|
|
|
|
2021-12-19 19:30:08 +01:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
2023-02-04 18:12:50 +01:00
|
|
|
@pytest_asyncio.fixture(scope="session")
|
2021-12-19 19:30:08 +01:00
|
|
|
async def shared_conn():
|
2023-11-27 23:24:35 +01:00
|
|
|
"""A database connection, ready to use."""
|
|
|
|
|
await db.open_connection_pool()
|
2021-12-19 19:30:08 +01:00
|
|
|
|
2023-11-27 23:24:35 +01:00
|
|
|
async with db.new_connection() as c:
|
|
|
|
|
db._test_connection = c
|
|
|
|
|
yield c
|
|
|
|
|
db._test_connection = None
|
2021-12-19 19:30:08 +01:00
|
|
|
|
2023-11-27 23:24:35 +01:00
|
|
|
await db.close_connection_pool()
|
2021-12-19 19:30:08 +01:00
|
|
|
|
|
|
|
|
|
2023-02-04 18:12:50 +01:00
|
|
|
@pytest_asyncio.fixture
|
2023-11-27 23:24:35 +01:00
|
|
|
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):
|
2021-12-19 19:30:08 +01:00
|
|
|
yield shared_conn
|