Skip to content

Commit 61b67d0

Browse files
committed
replace alt-pytest-asyncio with pytest-asyncio and fix AsyncClient call
1 parent b8776d3 commit 61b67d0

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ dependencies = [
2121
[dependency-groups]
2222
dev = [
2323
"asgi-lifespan",
24-
"alt-pytest-asyncio",
2524
"httpx[cli,http2]",
2625
"mypy",
2726
"pip-audit",
2827
"pytest",
28+
"pytest-asyncio",
2929
"pytest-cov",
3030
"ruff",
3131
]
3232

3333
[tool.pytest.ini_options]
34+
asyncio_mode = "auto"
35+
asyncio_default_test_loop_scope = "session"
36+
asyncio_default_fixture_loop_scope = "session"
3437
filterwarnings = ["ignore::DeprecationWarning"]
35-
default_async_timeout = 600
3638

3739
[tool.mypy]
3840
ignore_missing_imports = true

{{cookiecutter.project_slug}}/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from asgi_lifespan import LifespanManager
55
from fastapi import FastAPI
6-
from httpx import AsyncClient
6+
from httpx import ASGITransport, AsyncClient
77
from pytest import fixture
88

99
os.environ['ENV'] = 'testing'
@@ -22,5 +22,5 @@ async def app() -> AsyncIterable[FastAPI]:
2222

2323
@fixture
2424
async def client(app: FastAPI) -> AsyncIterable[AsyncClient]:
25-
async with AsyncClient(app=app, base_url='http://testserver') as client:
25+
async with AsyncClient(transport=ASGITransport(app=app), base_url='http://testserver') as client:
2626
yield client

{{cookiecutter.project_slug}}/tests/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from collections.abc import AsyncIterable
33

44
from fastapi import APIRouter, FastAPI, status
5-
from httpx import AsyncClient
5+
from httpx import ASGITransport, AsyncClient
66
from pytest import CaptureFixture, fixture
77

88
basic_log_fields = {
@@ -50,7 +50,7 @@ async def divide(a: int, b: int) -> float:
5050

5151
init_loguru()
5252

53-
async with AsyncClient(app=app, base_url='http://test_logging') as client:
53+
async with AsyncClient(transport=ASGITransport(app=app), base_url='http://test_logging') as client:
5454
yield client
5555

5656
return

0 commit comments

Comments
 (0)