maj via codex
This commit is contained in:
@@ -1,29 +1,39 @@
|
||||
import os
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlmodel import SQLModel, create_engine, Session
|
||||
from sqlmodel.pool import StaticPool
|
||||
|
||||
os.environ.setdefault("ENABLE_SCHEDULER", "0")
|
||||
os.environ.setdefault("ENABLE_BOOTSTRAP", "0")
|
||||
|
||||
import app.models # noqa — force l'enregistrement des modèles
|
||||
from app.main import app
|
||||
from app.database import get_session
|
||||
|
||||
|
||||
@pytest.fixture(name="session")
|
||||
def session_fixture():
|
||||
@pytest.fixture(name="engine")
|
||||
def engine_fixture():
|
||||
engine = create_engine(
|
||||
"sqlite://",
|
||||
connect_args={"check_same_thread": False},
|
||||
poolclass=StaticPool,
|
||||
)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
return engine
|
||||
|
||||
|
||||
@pytest.fixture(name="session")
|
||||
def session_fixture(engine):
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
||||
|
||||
@pytest.fixture(name="client")
|
||||
def client_fixture(session: Session):
|
||||
def client_fixture(engine):
|
||||
def get_session_override():
|
||||
yield session
|
||||
with Session(engine) as s:
|
||||
yield s
|
||||
|
||||
app.dependency_overrides[get_session] = get_session_override
|
||||
client = TestClient(app)
|
||||
|
||||
Reference in New Issue
Block a user