Skip to content

Commit

Permalink
Fix tests for new starlette version
Browse files Browse the repository at this point in the history
  • Loading branch information
vjousse committed Jan 7, 2023
1 parent 513294d commit 7740d74
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions app/tests/conftest.py
@@ -1,21 +1,29 @@
import asyncio
import os
from typing import Generator, Iterator

import pytest
from fastapi.testclient import TestClient
from tortoise.contrib.test import finalizer, initializer

from app.core.config import settings
from typing import Generator
from fastapi.testclient import TestClient
from app.main import app


@pytest.fixture(scope="module")
def client() -> Generator:
def event_loop() -> Iterator[asyncio.AbstractEventLoop]:
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()


# Test client
@pytest.fixture(scope="module")
def client(event_loop: asyncio.BaseEventLoop) -> Iterator[TestClient]:
db_url = os.environ.get("TORTOISE_TEST_DB", "sqlite://:memory:")
initializer(settings.TORTOISE_MODELS, db_url=db_url, app_label="models")
initializer(
settings.TORTOISE_MODELS, db_url=db_url, app_label="models", loop=event_loop
)
with TestClient(app) as c:
yield c
finalizer()


@pytest.fixture(scope="module")
def event_loop(client: TestClient) -> Generator:
yield client.task.get_loop()

0 comments on commit 7740d74

Please sign in to comment.