mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2025-06-05 21:59:23 +02:00
Tweak test suite
This commit is contained in:
@ -4,11 +4,11 @@ import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.database import Base
|
||||
from app.database import SessionLocal
|
||||
from app.database import async_engine
|
||||
from app.database import async_session
|
||||
from app.database import engine
|
||||
from app.main import app
|
||||
from tests.factories import _Session
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -25,28 +25,12 @@ async def async_db_session():
|
||||
def db() -> Generator:
|
||||
Base.metadata.create_all(bind=engine)
|
||||
try:
|
||||
yield SessionLocal()
|
||||
yield _Session
|
||||
finally:
|
||||
try:
|
||||
Base.metadata.drop_all(bind=engine)
|
||||
except Exception:
|
||||
# XXX: for some reason, the teardown occasionally fails because of this
|
||||
pass
|
||||
Base.metadata.drop_all(bind=engine)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def exclude_fastapi_middleware():
|
||||
"""Workaround for https://github.com/encode/starlette/issues/472"""
|
||||
user_middleware = app.user_middleware.copy()
|
||||
app.user_middleware = []
|
||||
app.middleware_stack = app.build_middleware_stack()
|
||||
yield
|
||||
app.user_middleware = user_middleware
|
||||
app.middleware_stack = app.build_middleware_stack()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(db, exclude_fastapi_middleware) -> Generator:
|
||||
# app.dependency_overrides[get_db] = _get_db_for_testing
|
||||
def client(db) -> Generator:
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
Reference in New Issue
Block a user