Skip to content

Commit

Permalink
Upgrade pytest-asyncio usage
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Mar 11, 2024
1 parent 48d4484 commit 352b22f
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 27 deletions.
7 changes: 0 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down
4 changes: 2 additions & 2 deletions tests/test_authentication_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import httpx
import pytest
import pytest_asyncio
from fastapi import Depends, FastAPI, Request, status
from fastapi.security.base import SecurityBase

Expand Down Expand Up @@ -66,8 +67,7 @@ def _get_backend_user(name: str = "user"):
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],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fastapi_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import httpx
import pytest
import pytest_asyncio
from fastapi import FastAPI, status

from fastapi_users.fastapi_users import FastAPIUsers
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_router_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import httpx
import pytest
import pytest_asyncio
from fastapi import FastAPI, status

from fastapi_users.authentication import Authenticator
Expand Down Expand Up @@ -39,10 +40,9 @@ def _app_factory(requires_verification: bool) -> FastAPI:
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]:
Expand Down
7 changes: 3 additions & 4 deletions tests/test_router_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import httpx
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_router_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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]:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_router_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import httpx
import pytest
import pytest_asyncio
from fastapi import FastAPI, status

from fastapi_users.exceptions import (
Expand All @@ -14,8 +15,7 @@
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]:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_router_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import httpx
import pytest
import pytest_asyncio
from fastapi import FastAPI, status

from fastapi_users.authentication import Authenticator
Expand Down Expand Up @@ -33,10 +34,9 @@ def _app_factory(requires_verification: bool) -> FastAPI:
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]:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_router_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import httpx
import pytest
import pytest_asyncio
from fastapi import FastAPI, status

from fastapi_users.exceptions import (
Expand All @@ -14,8 +15,7 @@
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,
Expand Down

0 comments on commit 352b22f

Please sign in to comment.