Fixtures
This commit is contained in:
@ -3,14 +3,17 @@ import logging
|
||||
from datetime import datetime
|
||||
from typing import AsyncGenerator
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from _pytest.config import Config
|
||||
from litestar.testing import AsyncTestClient
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
|
||||
from app.lib import settings
|
||||
from app.lib.sqlalchemy_plugin import DBConnectionSettings, create_db_engine
|
||||
from app.lib.test_extras.db_setup import TestingDatabaseSetup
|
||||
from main import app
|
||||
|
||||
# A Guide To Database Unit Testing with Pytest and SQLAlchemy
|
||||
# https://coderpad.io/blog/development/a-guide-to-database-unit-testing-with-pytest-and-sqlalchemy/
|
||||
@ -63,6 +66,11 @@ async def db_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
pytest_plugins = ()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def async_client() -> AsyncTestClient:
|
||||
return AsyncTestClient(app=app)
|
||||
|
||||
|
||||
def pytest_configure(config: Config) -> None:
|
||||
logging.info(f"Starting tests: {datetime.utcnow()}")
|
||||
db_setup = TestingDatabaseSetup(options=settings.testing)
|
||||
|
||||
Reference in New Issue
Block a user