27 lines
604 B
Python
27 lines
604 B
Python
from collections.abc import Iterator
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from dependencies import get_session
|
|
from main import app
|
|
from tests.fakes import FakeSession
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_session() -> FakeSession:
|
|
return FakeSession()
|
|
|
|
|
|
@pytest.fixture
|
|
def client(fake_session: FakeSession) -> Iterator[TestClient]:
|
|
def override_get_session() -> Iterator[FakeSession]:
|
|
yield fake_session
|
|
|
|
app.dependency_overrides[get_session] = override_get_session
|
|
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
|
|
app.dependency_overrides.clear()
|