-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
45 lines (32 loc) · 1.14 KB
/
conftest.py
File metadata and controls
45 lines (32 loc) · 1.14 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
"""Configuration for all tests."""
from collections.abc import AsyncIterator
from typing import Any
import py
import pytest
import pytest_asyncio
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession
from easterobot.bot import Easterobot
from easterobot.config import MConfig
@pytest.fixture(autouse=True)
def _add_bot(doctest_namespace: dict[str, Any], bot: Easterobot) -> None:
"""Update doctest namespace."""
doctest_namespace["bot"] = bot
doctest_namespace["engine"] = bot.engine
doctest_namespace["config"] = bot.config
@pytest.fixture
def bot(tmpdir: py.path.LocalPath) -> Easterobot:
"""Get a bot ready-to-use."""
return Easterobot.generate(str(tmpdir), env=True)
@pytest.fixture
def engine(bot: Easterobot) -> AsyncEngine:
"""Get a bot ready-to-use."""
return bot.engine
@pytest_asyncio.fixture
async def session(engine: AsyncEngine) -> AsyncIterator[AsyncSession]:
"""Get a bot ready-to-use."""
async with AsyncSession(engine, expire_on_commit=False) as session:
yield session
@pytest.fixture
def config(bot: Easterobot) -> MConfig:
"""Get a bot ready-to-use."""
return bot.config