-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathconftest.py
More file actions
53 lines (44 loc) · 1.53 KB
/
conftest.py
File metadata and controls
53 lines (44 loc) · 1.53 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from collections.abc import AsyncGenerator
import pytest
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sybil import Sybil
from sybil.parsers.rest import PythonCodeBlockParser
EXECUTABLE_DOCS = (
"usage/modeling/basics.rst",
"usage/modeling/inheritance.rst",
"usage/modeling/sqlmodel.rst",
"usage/modeling/types.rst",
"usage/repositories/advanced.rst",
"usage/repositories/basics.rst",
"usage/repositories/filtering.rst",
"usage/database_seeding.rst",
"usage/services.rst",
)
NON_EXECUTABLE_DOCS = (
"usage/caching.rst",
"usage/cli.rst",
"usage/frameworks/fastapi.rst",
"usage/frameworks/flask.rst",
"usage/frameworks/litestar.rst",
"usage/frameworks/sanic.rst",
"usage/frameworks/starlette.rst",
"usage/routing.rst",
)
@pytest.fixture(name="engine")
async def engine_fixture() -> AsyncGenerator[AsyncEngine, None]:
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
yield engine
await engine.dispose()
@pytest.fixture(name="db_session")
async def db_session_fixture(engine: AsyncEngine) -> AsyncGenerator[AsyncSession, None]:
async_session_factory: sessionmaker[AsyncSession] = sessionmaker(
engine, class_=AsyncSession, expire_on_commit=False
)
async with async_session_factory() as session:
yield session
pytest_collect_file = Sybil(
parsers=[PythonCodeBlockParser()],
patterns=EXECUTABLE_DOCS,
fixtures=["db_session", "engine"],
).pytest()