mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
enable anyio for unit tests
This commit is contained in:
parent
408b39ea99
commit
a8458be925
@ -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
|
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),
|
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).
|
on [thoughtworks](https://www.thoughtworks.com/radar/languages-and-frameworks?blipid=202104087).
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,9 +4,7 @@ import pytest
|
|||||||
from fastapi import status
|
from fastapi import status
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
|
||||||
# decorate all tests with @pytest.mark.asyncio
|
pytestmark = pytest.mark.anyio
|
||||||
pytestmark = pytest.mark.asyncio
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"payload, status_code",
|
"payload, status_code",
|
||||||
|
@ -10,6 +10,16 @@ from the_app.database import get_db
|
|||||||
from the_app.main import app
|
from the_app.main import app
|
||||||
from the_app.models.base import Base
|
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()
|
global_settings = config.get_settings()
|
||||||
url = global_settings.asyncpg_test_url
|
url = global_settings.asyncpg_test_url
|
||||||
engine = create_async_engine(url, poolclass=NullPool, future=True)
|
engine = create_async_engine(url, poolclass=NullPool, future=True)
|
||||||
@ -41,9 +51,9 @@ async def start_db():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def client() -> AsyncClient:
|
async def client() -> AsyncClient:
|
||||||
async with AsyncClient(
|
async with AsyncClient(
|
||||||
app=app,
|
app=app,
|
||||||
base_url="http://testserver/v1",
|
base_url="http://testserver/v1",
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
) as client:
|
) as client:
|
||||||
await start_db()
|
await start_db()
|
||||||
yield client
|
yield client
|
||||||
|
Loading…
x
Reference in New Issue
Block a user