From a6d31bd42bafd9e3f35e5e146ec961c5bac3c18d Mon Sep 17 00:00:00 2001 From: grillazz Date: Sat, 27 Nov 2021 19:13:06 +0100 Subject: [PATCH] enable anyio for unit tests --- README.md | 2 +- tests/api/test_stuff.py | 4 +--- tests/conftest.py | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 389c52e..78e439f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Example for [FastAPI](https://fastapi.tiangolo.com/) integration with [SQLAlchem Beside of using latest and greatest version of [SQLAlchemy](https://www.sqlalchemy.org/) with it robustness, powerfulness and speed of [asyncpg](https://github.com/MagicStack/asyncpg) there is [FastAPI](https://fastapi.tiangolo.com/) (modern, fast (high-performance), -web framework for building APIs with Python 3.9+ based on standard Python type hints.) already reviewed +web framework for building APIs with Python 3.10+ based on standard Python type hints.) already reviewed on [thoughtworks](https://www.thoughtworks.com/radar/languages-and-frameworks?blipid=202104087). diff --git a/tests/api/test_stuff.py b/tests/api/test_stuff.py index aa039e5..c0656db 100644 --- a/tests/api/test_stuff.py +++ b/tests/api/test_stuff.py @@ -4,9 +4,7 @@ import pytest from fastapi import status from httpx import AsyncClient -# decorate all tests with @pytest.mark.asyncio -pytestmark = pytest.mark.asyncio - +pytestmark = pytest.mark.anyio @pytest.mark.parametrize( "payload, status_code", diff --git a/tests/conftest.py b/tests/conftest.py index 4fcf732..68e9243 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,6 +10,16 @@ from the_app.database import get_db from the_app.main import app from the_app.models.base import Base + +@pytest.fixture( + params=[ + pytest.param(("asyncio", {"use_uvloop": True}), id="asyncio+uvloop"), + ] +) +def anyio_backend(request): + return request.param + + global_settings = config.get_settings() url = global_settings.asyncpg_test_url engine = create_async_engine(url, poolclass=NullPool, future=True) @@ -41,9 +51,9 @@ async def start_db(): @pytest.fixture async def client() -> AsyncClient: async with AsyncClient( - app=app, - base_url="http://testserver/v1", - headers={"Content-Type": "application/json"}, + app=app, + base_url="http://testserver/v1", + headers={"Content-Type": "application/json"}, ) as client: await start_db() yield client