This repository has been archived on 2026-07-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core-hub/tests/conftest.py

42 lines
1.2 KiB
Python

import pytest
from fastapi.testclient import TestClient
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
import core_hub.models # noqa: F401
from core_hub.app import create_app
from core_hub.config import get_settings
from core_hub.db import Base, get_engine, get_sessionmaker
@pytest.fixture
def app(monkeypatch, tmp_path):
monkeypatch.setenv("CORE_HUB_DATABASE_URL", f"sqlite+aiosqlite:///{tmp_path / 'core-hub.db'}")
monkeypatch.setenv("CORE_HUB_API_TOKEN", "operator-token")
monkeypatch.setenv("CORE_HUB_AUTO_CREATE_TABLES", "1")
get_settings.cache_clear()
get_engine.cache_clear()
get_sessionmaker.cache_clear()
try:
yield create_app()
finally:
get_settings.cache_clear()
get_engine.cache_clear()
get_sessionmaker.cache_clear()
@pytest.fixture
def client(app):
with TestClient(app) as test_client:
yield test_client
@pytest.fixture
async def sqlite_engine() -> AsyncEngine:
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
async with engine.begin() as connection:
await connection.run_sync(Base.metadata.create_all)
try:
yield engine
finally:
await engine.dispose()