From b94179e07138ede8f4203bab922f64c0a62b5e85 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Wed, 11 Aug 2021 21:09:10 +0300 Subject: [PATCH] use asyncmock from unittest library --- tests/ahriman/conftest.py | 16 ---------------- .../web/middlewares/test_exception_handler.py | 7 ++++--- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/tests/ahriman/conftest.py b/tests/ahriman/conftest.py index 309a9e77..185d1858 100644 --- a/tests/ahriman/conftest.py +++ b/tests/ahriman/conftest.py @@ -42,22 +42,6 @@ def anyvar(cls: Type[T], strict: bool = False) -> T: return AnyVar() -@pytest.helpers.register -class AsyncMock(MagicMock): - """ - async magic mock object - """ - - async def __call__(self, *args: Any, **kwargs: Any) -> Any: - """ - async call function - :param args: - :param kwargs: - :return: - """ - return MagicMock.__call__(self, *args, **kwargs) - - # generic fixtures @pytest.fixture def configuration(resource_path_root: Path) -> Configuration: diff --git a/tests/ahriman/web/middlewares/test_exception_handler.py b/tests/ahriman/web/middlewares/test_exception_handler.py index 22e9aa3d..11b9c6c9 100644 --- a/tests/ahriman/web/middlewares/test_exception_handler.py +++ b/tests/ahriman/web/middlewares/test_exception_handler.py @@ -4,6 +4,7 @@ import pytest from aiohttp.web_exceptions import HTTPBadRequest from pytest_mock import MockerFixture from typing import Any +from unittest.mock import AsyncMock from ahriman.web.middlewares.exception_handler import exception_handler @@ -12,7 +13,7 @@ async def test_exception_handler(aiohttp_request: Any, mocker: MockerFixture) -> """ must pass success response """ - request_handler = pytest.helpers.AsyncMock() + request_handler = AsyncMock() logging_mock = mocker.patch("logging.Logger.exception") handler = exception_handler(logging.getLogger()) @@ -24,7 +25,7 @@ async def test_exception_handler_client_error(aiohttp_request: Any, mocker: Mock """ must pass client exception """ - request_handler = pytest.helpers.AsyncMock() + request_handler = AsyncMock() request_handler.side_effect = HTTPBadRequest() logging_mock = mocker.patch("logging.Logger.exception") @@ -38,7 +39,7 @@ async def test_exception_handler_server_error(aiohttp_request: Any, mocker: Mock """ must log server exception and re-raise it """ - request_handler = pytest.helpers.AsyncMock() + request_handler = AsyncMock() request_handler.side_effect = Exception() logging_mock = mocker.patch("logging.Logger.exception")