mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 11:11:16 +08:00
Upgrade pytest-asyncio usage
This commit is contained in:
@ -126,13 +126,6 @@ class UserManagerMock(BaseTestUserManager[models.UP]):
|
|||||||
_update: MagicMock
|
_update: MagicMock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def event_loop():
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
yield loop
|
|
||||||
loop.close()
|
|
||||||
|
|
||||||
|
|
||||||
AsyncMethodMocker = Callable[..., MagicMock]
|
AsyncMethodMocker = Callable[..., MagicMock]
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ from typing import AsyncGenerator, Generic, List, Optional, Sequence
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import Depends, FastAPI, Request, status
|
from fastapi import Depends, FastAPI, Request, status
|
||||||
from fastapi.security.base import SecurityBase
|
from fastapi.security.base import SecurityBase
|
||||||
|
|
||||||
@ -66,8 +67,7 @@ def get_backend_user(user: UserModel):
|
|||||||
return _get_backend_user
|
return _get_backend_user
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
def get_test_auth_client(get_user_manager, get_test_client):
|
def get_test_auth_client(get_user_manager, get_test_client):
|
||||||
async def _get_test_auth_client(
|
async def _get_test_auth_client(
|
||||||
backends: List[AuthenticationBackend],
|
backends: List[AuthenticationBackend],
|
||||||
|
@ -2,14 +2,14 @@ from typing import AsyncGenerator, Optional
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import Depends, FastAPI, status
|
from fastapi import Depends, FastAPI, status
|
||||||
|
|
||||||
from fastapi_users import FastAPIUsers, schemas
|
from fastapi_users import FastAPIUsers, schemas
|
||||||
from tests.conftest import IDType, User, UserCreate, UserModel, UserUpdate
|
from tests.conftest import IDType, User, UserCreate, UserModel, UserUpdate
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(
|
async def test_app_client(
|
||||||
secret,
|
secret,
|
||||||
get_user_manager,
|
get_user_manager,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
|
|
||||||
from fastapi_users.fastapi_users import FastAPIUsers
|
from fastapi_users.fastapi_users import FastAPIUsers
|
||||||
@ -28,8 +29,7 @@ def test_app(
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(test_app, get_test_client):
|
async def test_app_client(test_app, get_test_client):
|
||||||
async for client in get_test_client(test_app):
|
async for client in get_test_client(test_app):
|
||||||
yield client
|
yield client
|
||||||
|
@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, Tuple, cast
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
|
|
||||||
from fastapi_users.authentication import Authenticator
|
from fastapi_users.authentication import Authenticator
|
||||||
@ -39,10 +40,9 @@ def app_factory(get_user_manager, mock_authentication):
|
|||||||
return _app_factory
|
return _app_factory
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest_asyncio.fixture(
|
||||||
params=[True, False], ids=["required_verification", "not_required_verification"]
|
params=[True, False], ids=["required_verification", "not_required_verification"]
|
||||||
)
|
)
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(
|
async def test_app_client(
|
||||||
request, get_test_client, app_factory
|
request, get_test_client, app_factory
|
||||||
) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]:
|
) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]:
|
||||||
|
@ -2,6 +2,7 @@ from typing import Any, Dict, cast
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2
|
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2
|
||||||
|
|
||||||
@ -69,15 +70,13 @@ def test_app_requires_verification(app_factory):
|
|||||||
return app_factory(requires_verification=True)
|
return app_factory(requires_verification=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(test_app, get_test_client):
|
async def test_app_client(test_app, get_test_client):
|
||||||
async for client in get_test_client(test_app):
|
async for client in get_test_client(test_app):
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client_redirect_url(test_app_redirect_url, get_test_client):
|
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):
|
async for client in get_test_client(test_app_redirect_url):
|
||||||
yield client
|
yield client
|
||||||
|
@ -2,14 +2,14 @@ from typing import Any, AsyncGenerator, Dict, cast
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
|
|
||||||
from fastapi_users.router import ErrorCode, get_register_router
|
from fastapi_users.router import ErrorCode, get_register_router
|
||||||
from tests.conftest import User, UserCreate
|
from tests.conftest import User, UserCreate
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(
|
async def test_app_client(
|
||||||
get_user_manager, get_test_client
|
get_user_manager, get_test_client
|
||||||
) -> AsyncGenerator[httpx.AsyncClient, None]:
|
) -> AsyncGenerator[httpx.AsyncClient, None]:
|
||||||
|
@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, cast
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
|
|
||||||
from fastapi_users.exceptions import (
|
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
|
from tests.conftest import AsyncMethodMocker, UserManagerMock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(
|
async def test_app_client(
|
||||||
get_user_manager, get_test_client
|
get_user_manager, get_test_client
|
||||||
) -> AsyncGenerator[httpx.AsyncClient, None]:
|
) -> AsyncGenerator[httpx.AsyncClient, None]:
|
||||||
|
@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, Tuple, cast
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
|
|
||||||
from fastapi_users.authentication import Authenticator
|
from fastapi_users.authentication import Authenticator
|
||||||
@ -33,10 +34,9 @@ def app_factory(get_user_manager, mock_authentication):
|
|||||||
return _app_factory
|
return _app_factory
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest_asyncio.fixture(
|
||||||
params=[True, False], ids=["required_verification", "not_required_verification"]
|
params=[True, False], ids=["required_verification", "not_required_verification"]
|
||||||
)
|
)
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(
|
async def test_app_client(
|
||||||
request, get_test_client, app_factory
|
request, get_test_client, app_factory
|
||||||
) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]:
|
) -> AsyncGenerator[Tuple[httpx.AsyncClient, bool], None]:
|
||||||
|
@ -2,6 +2,7 @@ from typing import Any, AsyncGenerator, Dict, cast
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
|
|
||||||
from fastapi_users.exceptions import (
|
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
|
from tests.conftest import AsyncMethodMocker, User, UserManagerMock, UserModel
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest_asyncio.fixture
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_app_client(
|
async def test_app_client(
|
||||||
get_user_manager,
|
get_user_manager,
|
||||||
get_test_client,
|
get_test_client,
|
||||||
|
Reference in New Issue
Block a user