diff --git a/tests/conftest.py b/tests/conftest.py index 2ae43dc1..0cf63a46 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -126,13 +126,6 @@ class UserManagerMock(BaseTestUserManager[models.UP]): _update: MagicMock -@pytest.fixture(scope="session") -def event_loop(): - loop = asyncio.get_event_loop() - yield loop - loop.close() - - AsyncMethodMocker = Callable[..., MagicMock] diff --git a/tests/test_authentication_authenticator.py b/tests/test_authentication_authenticator.py index d2ee48e2..baec8724 100644 --- a/tests/test_authentication_authenticator.py +++ b/tests/test_authentication_authenticator.py @@ -2,6 +2,7 @@ from typing import AsyncGenerator, Generic, List, Optional, Sequence import httpx import pytest +import pytest_asyncio from fastapi import Depends, FastAPI, Request, status from fastapi.security.base import SecurityBase @@ -66,8 +67,7 @@ def get_backend_user(user: UserModel): return _get_backend_user -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture def get_test_auth_client(get_user_manager, get_test_client): async def _get_test_auth_client( backends: List[AuthenticationBackend], diff --git a/tests/test_fastapi_users.py b/tests/test_fastapi_users.py index 5b12de6d..a42aa78a 100644 --- a/tests/test_fastapi_users.py +++ b/tests/test_fastapi_users.py @@ -2,14 +2,14 @@ from typing import AsyncGenerator, Optional import httpx import pytest +import pytest_asyncio from fastapi import Depends, FastAPI, status from fastapi_users import FastAPIUsers, schemas from tests.conftest import IDType, User, UserCreate, UserModel, UserUpdate -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture async def test_app_client( secret, get_user_manager, diff --git a/tests/test_openapi.py b/tests/test_openapi.py index 439da25d..3f167f38 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -1,5 +1,6 @@ import httpx import pytest +import pytest_asyncio from fastapi import FastAPI, status from fastapi_users.fastapi_users import FastAPIUsers @@ -28,8 +29,7 @@ def test_app( return app -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture async def test_app_client(test_app, get_test_client): async for client in get_test_client(test_app): yield client diff --git a/tests/test_router_auth.py b/tests/test_router_auth.py index 4cc65075..8e648b57 100644 --- a/tests/test_router_auth.py +++ b/tests/test_router_auth.py @@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, Tuple, cast import httpx import pytest +import pytest_asyncio from fastapi import FastAPI, status from fastapi_users.authentication import Authenticator @@ -39,10 +40,9 @@ def app_factory(get_user_manager, mock_authentication): return _app_factory -@pytest.fixture( +@pytest_asyncio.fixture( params=[True, False], ids=["required_verification", "not_required_verification"] ) -@pytest.mark.asyncio async def test_app_client( request, get_test_client, app_factory ) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]: diff --git a/tests/test_router_oauth.py b/tests/test_router_oauth.py index 22c9a8d3..50ed3ad1 100644 --- a/tests/test_router_oauth.py +++ b/tests/test_router_oauth.py @@ -2,6 +2,7 @@ from typing import Any, Dict, cast import httpx import pytest +import pytest_asyncio from fastapi import FastAPI, status from httpx_oauth.oauth2 import BaseOAuth2, OAuth2 @@ -69,15 +70,13 @@ def test_app_requires_verification(app_factory): return app_factory(requires_verification=True) -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture async def test_app_client(test_app, get_test_client): async for client in get_test_client(test_app): yield client -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture async def test_app_client_redirect_url(test_app_redirect_url, get_test_client): async for client in get_test_client(test_app_redirect_url): yield client diff --git a/tests/test_router_register.py b/tests/test_router_register.py index 7cc0af4f..50f0f61b 100644 --- a/tests/test_router_register.py +++ b/tests/test_router_register.py @@ -2,14 +2,14 @@ from typing import Any, AsyncGenerator, Dict, cast import httpx import pytest +import pytest_asyncio from fastapi import FastAPI, status from fastapi_users.router import ErrorCode, get_register_router from tests.conftest import User, UserCreate -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture async def test_app_client( get_user_manager, get_test_client ) -> AsyncGenerator[httpx.AsyncClient, None]: diff --git a/tests/test_router_reset.py b/tests/test_router_reset.py index fdfbb378..55c8b453 100644 --- a/tests/test_router_reset.py +++ b/tests/test_router_reset.py @@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, cast import httpx import pytest +import pytest_asyncio from fastapi import FastAPI, status from fastapi_users.exceptions import ( @@ -14,8 +15,7 @@ from fastapi_users.router import ErrorCode, get_reset_password_router from tests.conftest import AsyncMethodMocker, UserManagerMock -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture async def test_app_client( get_user_manager, get_test_client ) -> AsyncGenerator[httpx.AsyncClient, None]: diff --git a/tests/test_router_users.py b/tests/test_router_users.py index eda71f37..b6427c50 100644 --- a/tests/test_router_users.py +++ b/tests/test_router_users.py @@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, Tuple, cast import httpx import pytest +import pytest_asyncio from fastapi import FastAPI, status from fastapi_users.authentication import Authenticator @@ -33,10 +34,9 @@ def app_factory(get_user_manager, mock_authentication): return _app_factory -@pytest.fixture( +@pytest_asyncio.fixture( params=[True, False], ids=["required_verification", "not_required_verification"] ) -@pytest.mark.asyncio async def test_app_client( request, get_test_client, app_factory ) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]: diff --git a/tests/test_router_verify.py b/tests/test_router_verify.py index 488135ba..e798e84a 100644 --- a/tests/test_router_verify.py +++ b/tests/test_router_verify.py @@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, cast import httpx import pytest +import pytest_asyncio from fastapi import FastAPI, status from fastapi_users.exceptions import ( @@ -14,8 +15,7 @@ from fastapi_users.router import ErrorCode, get_verify_router from tests.conftest import AsyncMethodMocker, User, UserManagerMock, UserModel -@pytest.fixture -@pytest.mark.asyncio +@pytest_asyncio.fixture async def test_app_client( get_user_manager, get_test_client,