Skip to content

Commit 352b22f

Browse files
committed
Upgrade pytest-asyncio usage
1 parent 48d4484 commit 352b22f

10 files changed

+19
-27
lines changed

tests/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,6 @@ class UserManagerMock(BaseTestUserManager[models.UP]):
126126
_update: MagicMock
127127

128128

129-
@pytest.fixture(scope="session")
130-
def event_loop():
131-
loop = asyncio.get_event_loop()
132-
yield loop
133-
loop.close()
134-
135-
136129
AsyncMethodMocker = Callable[..., MagicMock]
137130

138131

tests/test_authentication_authenticator.py

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

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import Depends, FastAPI, Request, status
67
from fastapi.security.base import SecurityBase
78

@@ -66,8 +67,7 @@ def _get_backend_user(name: str = "user"):
6667
return _get_backend_user
6768

6869

69-
@pytest.fixture
70-
@pytest.mark.asyncio
70+
@pytest_asyncio.fixture
7171
def get_test_auth_client(get_user_manager, get_test_client):
7272
async def _get_test_auth_client(
7373
backends: List[AuthenticationBackend],

tests/test_fastapi_users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import Depends, FastAPI, status
67

78
from fastapi_users import FastAPIUsers, schemas
89
from tests.conftest import IDType, User, UserCreate, UserModel, UserUpdate
910

1011

11-
@pytest.fixture
12-
@pytest.mark.asyncio
12+
@pytest_asyncio.fixture
1313
async def test_app_client(
1414
secret,
1515
get_user_manager,

tests/test_openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import httpx
22
import pytest
3+
import pytest_asyncio
34
from fastapi import FastAPI, status
45

56
from fastapi_users.fastapi_users import FastAPIUsers
@@ -28,8 +29,7 @@ def test_app(
2829
return app
2930

3031

31-
@pytest.fixture
32-
@pytest.mark.asyncio
32+
@pytest_asyncio.fixture
3333
async def test_app_client(test_app, get_test_client):
3434
async for client in get_test_client(test_app):
3535
yield client

tests/test_router_auth.py

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

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import FastAPI, status
67

78
from fastapi_users.authentication import Authenticator
@@ -39,10 +40,9 @@ def _app_factory(requires_verification: bool) -> FastAPI:
3940
return _app_factory
4041

4142

42-
@pytest.fixture(
43+
@pytest_asyncio.fixture(
4344
params=[True, False], ids=["required_verification", "not_required_verification"]
4445
)
45-
@pytest.mark.asyncio
4646
async def test_app_client(
4747
request, get_test_client, app_factory
4848
) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]:

tests/test_router_oauth.py

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

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import FastAPI, status
67
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2
78

@@ -69,15 +70,13 @@ def test_app_requires_verification(app_factory):
6970
return app_factory(requires_verification=True)
7071

7172

72-
@pytest.fixture
73-
@pytest.mark.asyncio
73+
@pytest_asyncio.fixture
7474
async def test_app_client(test_app, get_test_client):
7575
async for client in get_test_client(test_app):
7676
yield client
7777

7878

79-
@pytest.fixture
80-
@pytest.mark.asyncio
79+
@pytest_asyncio.fixture
8180
async def test_app_client_redirect_url(test_app_redirect_url, get_test_client):
8281
async for client in get_test_client(test_app_redirect_url):
8382
yield client

tests/test_router_register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import FastAPI, status
67

78
from fastapi_users.router import ErrorCode, get_register_router
89
from tests.conftest import User, UserCreate
910

1011

11-
@pytest.fixture
12-
@pytest.mark.asyncio
12+
@pytest_asyncio.fixture
1313
async def test_app_client(
1414
get_user_manager, get_test_client
1515
) -> AsyncGenerator[httpx.AsyncClient, None]:

tests/test_router_reset.py

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

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import FastAPI, status
67

78
from fastapi_users.exceptions import (
@@ -14,8 +15,7 @@
1415
from tests.conftest import AsyncMethodMocker, UserManagerMock
1516

1617

17-
@pytest.fixture
18-
@pytest.mark.asyncio
18+
@pytest_asyncio.fixture
1919
async def test_app_client(
2020
get_user_manager, get_test_client
2121
) -> AsyncGenerator[httpx.AsyncClient, None]:

tests/test_router_users.py

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

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import FastAPI, status
67

78
from fastapi_users.authentication import Authenticator
@@ -33,10 +34,9 @@ def _app_factory(requires_verification: bool) -> FastAPI:
3334
return _app_factory
3435

3536

36-
@pytest.fixture(
37+
@pytest_asyncio.fixture(
3738
params=[True, False], ids=["required_verification", "not_required_verification"]
3839
)
39-
@pytest.mark.asyncio
4040
async def test_app_client(
4141
request, get_test_client, app_factory
4242
) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]:

tests/test_router_verify.py

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

33
import httpx
44
import pytest
5+
import pytest_asyncio
56
from fastapi import FastAPI, status
67

78
from fastapi_users.exceptions import (
@@ -14,8 +15,7 @@
1415
from tests.conftest import AsyncMethodMocker, User, UserManagerMock, UserModel
1516

1617

17-
@pytest.fixture
18-
@pytest.mark.asyncio
18+
@pytest_asyncio.fixture
1919
async def test_app_client(
2020
get_user_manager,
2121
get_test_client,

0 commit comments

Comments
 (0)