Skip to main content

A library for testing your bots on aiogram

Project description

Aiogram Tests

aiogram_tests is a testing library for bots written on aiogram

📚 Simple examples

Simple handler test

Simple bot:

from aiogram import Bot, Dispatcher, types
from aiogram.fsm.context import FSMContext

# Please, keep your bot tokens on environments, this code only example
bot = Bot('123456789:AABBCCDDEEFFaabbccddeeff-1234567890')
dp = Dispatcher()


@dp.message()
async def echo(message: types.Message, state: FSMContext) -> None:
    await message.answer(message.text)


if __name__ == '__main__':
    dp.run_polling(bot)

Test cases:

import pytest

from bot import echo

from aiogram_tests import MockedBot
from aiogram_tests.handler import MessageHandler
from aiogram_tests.types.dataset import MESSAGE


@pytest.mark.asyncio
async def test_echo():
    request = MockedBot(MessageHandler(echo))
    calls = await request.query(message=MESSAGE.as_object(text="Hello, Bot!"))
    answer_message = calls.send_messsage.fetchone()
    assert answer_message.text == "Hello, Bot!"

▶️ More examples

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiogram_tests-1.0.3.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

aiogram_tests-1.0.3-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_tests-1.0.3.tar.gz.

File metadata

  • Download URL: aiogram_tests-1.0.3.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for aiogram_tests-1.0.3.tar.gz
Algorithm Hash digest
SHA256 cdc78e9a65e205a744e944361a844c0f764f7777718dde087821000d49d354b3
MD5 646bdb3cc8866cec7b33b9a90f9c86d0
BLAKE2b-256 460e5cd670e9a05fb1b66d1b860b500784c352758f618e5171ac6de88185e94a

See more details on using hashes here.

File details

Details for the file aiogram_tests-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for aiogram_tests-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b92fc4dbb652ed115bbcef08d2e020a8e86e575217fb44876d926b5cd681aca0
MD5 70700cb230859b3fe67fcb72e34f1900
BLAKE2b-256 8a892537d3596abba90c09c977cb921b2c9d1013df8a1250761cf5d26c5605c5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page