New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples how to test your bot #378
Comments
My $0.01 on testing. |
Well, I was thinking there is something to help me create telegram updates with different messages, to pass to my dispatcher.
Testing each handler separatly also can work, but I am using state features, and not sure how to setup it.
For me any examples will help a lot.
|
@sazarkin try to use bot\__main__.py from bot.handlers import echo_handler
...
if __name__ == '__main__':
echo_handler.setup(dp)
executor.start_polling(dp, skip_updates=True) bot\handlers\echo_handler.py from aiogram import types, Dispatcher
async def echo(message: types.Message):
await message.answer(message.text)
def setup(dp: Dispatcher):
dp.register_message_handler(echo) bot\tests\handlers\test_echo_handler.py import pytest
from unittest.mock import AsyncMock
from bot.handlers.echo_handler import echo
@pytest.mark.asyncio
async def test_echo_handler():
text_mock = "test123"
message_mock = AsyncMock(text=text_mock)
await echo(message=message_mock)
message_mock.answer.assert_called_with(text_mock) |
I can test different handlers, but I don't know how to test routers' logic. I mean how I can send a mocked message with a defined router (routers' chain) end to assert an answer from some handler? |
Currently, aiogram_tests is broken. I have found a fork that does work with aiogram 3.3.0. |
Hello!
Thanks for awesome library.
I am trying to write tests for my bot, and not sure how to do it right. I've searched the docs but found nothing.
Do you have some examples?
The text was updated successfully, but these errors were encountered: