-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
38 lines (32 loc) · 1.11 KB
/
Copy pathconftest.py
File metadata and controls
38 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
An example of fast-running tests, as the transaction for both the test and
the application is shared.
This allows data isolation to be achieved by rolling back the transaction
rather than deleting data from tables.
It's not exactly fair testing, because the app doesn't manage the session
itself.
But for most basic tests, it's sufficient.
On the plus side, these tests run faster.
"""
from collections.abc import AsyncGenerator
import pytest_asyncio
from sqlalchemy.ext.asyncio import AsyncSession
from context_async_sqlalchemy.test_utils import (
put_savepoint_session_in_ctx,
set_test_context,
)
from examples.database import connection
@pytest_asyncio.fixture(autouse=True)
async def db_session_override(
db_session_test: AsyncSession,
) -> AsyncGenerator[None]:
"""
The key thing about these tests is that we override the context in advance.
The middleware has a special check that won't initialize the context
if it already exists.
"""
async with (
set_test_context(),
put_savepoint_session_in_ctx(connection, db_session_test),
):
yield