diff --git a/aiogram/dispatcher/filters/base.py b/aiogram/dispatcher/filters/base.py index ce7b007c..fabaaf21 100644 --- a/aiogram/dispatcher/filters/base.py +++ b/aiogram/dispatcher/filters/base.py @@ -17,5 +17,6 @@ class BaseFilter(ABC, BaseModel): async def __call__(self, *args: Any, **kwargs: Any) -> Union[bool, Dict[str, Any]]: pass - def __await__(self): + def __await__(self): # pragma: no cover + # Is needed only for inspection and this method is never be called return self.__call__ diff --git a/tests/test_dispatcher/test_filters/test_base.py b/tests/test_dispatcher/test_filters/test_base.py new file mode 100644 index 00000000..dd183fb5 --- /dev/null +++ b/tests/test_dispatcher/test_filters/test_base.py @@ -0,0 +1,30 @@ +from typing import Awaitable +from unittest.mock import patch + +import pytest +from asynctest import CoroutineMock + +from aiogram.dispatcher.filters.base import BaseFilter + + +class MyFilter(BaseFilter): + foo: str + + async def __call__(self, event: str): + return + + +class TestBaseFilter: + @pytest.mark.asyncio + async def test_awaitable(self): + my_filter = MyFilter(foo="bar") + + assert isinstance(my_filter, Awaitable) + + with patch( + "tests.test_dispatcher.test_filters.test_base.MyFilter.__call__", + new_callable=CoroutineMock, + ) as mocked_call: + call = my_filter(event="test") + await call + mocked_call.assert_awaited_with(event="test")