Код: Выделить всё
import pytest
from fastapi.testclient import TestClient
from tortoise.contrib.test import finalizer, initializer
import app.main as main
from app.core.config import settings
@pytest.fixture(scope="session", autouse=True)
def initialize_tests(request):
db_url = "postgres://USERNAME_HERE:SECRET_PASS_HERE@127.0.0.1:5432/test"
initializer(
[
"app.models",
],
db_url=db_url,
app_label="models"
)
print("initialize_tests")
request.add_finaliser(finalizer)
@pytest.fixture(scope="session")
def client():
app = main.create_application()
with TestClient(app) as client:
print("client")
yield client
Код: Выделить всё
def test_get(client):
response = client.get("/v1/url/")
assert response.status_code == 200
Код: Выделить всё
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress
Тестирование в FastAPI с использованием Tortoise-ORM
https://stackoverflow. com/a/66907531
Но это не похоже на четкое решение.
Вопрос: есть ли способ заставить тесты работать с использованием инициализатора и финализатора?
Подробнее здесь: https://stackoverflow.com/questions/730 ... rtoise-orm
Мобильная версия