use asyncmock from unittest library

This commit is contained in:
Evgenii Alekseev 2021-08-11 21:09:10 +03:00
parent 9c5a9f5837
commit b94179e071
2 changed files with 4 additions and 19 deletions

View File

@ -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:

View File

@ -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")