typehint в app и conftest
parent
bde9581090
commit
e378bf1da1
|
@ -61,7 +61,7 @@ tags_metadata = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app() -> FastAPI:
|
||||||
"""
|
"""
|
||||||
Фабрика FastAPI.
|
Фабрика FastAPI.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator, Generator
|
||||||
from httpx import AsyncClient
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
from sqlalchemy.ext.asyncio import (
|
from fastapi import FastAPI
|
||||||
AsyncSession,
|
from httpx import AsyncClient
|
||||||
async_sessionmaker,
|
from sqlalchemy.ext.asyncio import (AsyncSession, async_sessionmaker,
|
||||||
create_async_engine,
|
create_async_engine)
|
||||||
)
|
|
||||||
from fastfood.app import create_app
|
|
||||||
|
|
||||||
|
from fastfood.app import create_app
|
||||||
from fastfood.config import settings
|
from fastfood.config import settings
|
||||||
from fastfood.dbase import get_async_session
|
from fastfood.dbase import get_async_session
|
||||||
from fastfood.models import Base
|
from fastfood.models import Base
|
||||||
|
|
||||||
|
|
||||||
async_engine = create_async_engine(settings.TESTDATABASE_URL_asyncpg)
|
async_engine = create_async_engine(settings.TESTDATABASE_URL_asyncpg)
|
||||||
async_session_maker = async_sessionmaker(
|
async_session_maker = async_sessionmaker(
|
||||||
async_engine,
|
async_engine,
|
||||||
|
@ -49,16 +47,17 @@ async def get_test_session() -> AsyncGenerator[AsyncSession, None]:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def app():
|
def app() -> Generator[FastAPI, None, None]:
|
||||||
app = create_app()
|
app: FastAPI = create_app()
|
||||||
app.dependency_overrides[get_async_session] = get_test_session
|
app.dependency_overrides[get_async_session] = get_test_session
|
||||||
yield app
|
yield app
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture(scope="function")
|
@pytest_asyncio.fixture(scope="function")
|
||||||
async def client(app):
|
async def client(app) -> AsyncGenerator[AsyncClient, None]:
|
||||||
async with AsyncClient(
|
async with AsyncClient(
|
||||||
app=app, base_url="http://localhost:8000/api/v1/menus",
|
app=app,
|
||||||
|
base_url="http://localhost:8000/api/v1/menus",
|
||||||
) as async_client:
|
) as async_client:
|
||||||
yield async_client
|
yield async_client
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue