aiogram_bot_tester
Your missing test toolkit for Telegram bots.
[!WARNING] This library is under active development. Its API is unstable and may contain frequent breaking changes between releases.
Installation
Stable version:
pip install aiogram_bot_tester
Latest development version:
pip install git+https://github.com/samedit66/aiogram-bot-tester.git
What's that?
aiogram_bot_tester is a lightweight way to test aiogram bots offline, without real Telegram API calls. It helps you simulate updates, check bot responses, and keep tests deterministic, so bot logic can be covered with confidence even when the conversation flow is complex.
Features
- Fully offline testing — run bot scenarios without a Telegram token, network requests, or real API calls.
- Real aiogram pipeline — updates pass through the actual dispatcher, routers, filters, middleware, and FSM machinery.
- Conversation-first API — send messages and commands, start the bot, and tap reply or callback buttons by their visible labels.
- Readable assertions — check message text, regular expressions, buttons, callback data, URLs, and complete keyboard layouts.
- FSM support — assert the current state and inspect FSM data across multi-step conversation flows.
- Flexible test setup — build a tester from reusable routers or an existing dispatcher, pass fake dependencies directly, and attach middleware when needed.
Quick example
import pytest
import aiogram
from aiogram import F
from aiogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message
from aiogram_bot_tester import BotTester
router = aiogram.Router()
@router.message(aiogram.filters.CommandStart())
async def cmd_start(message: Message) -> None:
await message.answer(
"Hello! Press Continue or send me your name.",
reply_markup=InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(text="Continue", callback_data="continue")]
]
),
)
@router.message(F.text)
async def echo_name(message: Message) -> None:
await message.answer(f"Nice to meet you, {message.text}!")
@router.callback_query(F.data == "continue")
async def on_continue(callback: CallbackQuery) -> None:
await callback.message.answer("Please send your name.")
@pytest.mark.asyncio
async def test_flow() -> None:
tester = BotTester.from_routers(router)
response = await tester.start()
response.assert_contains("Hello")
response.assert_button("Continue")
response = await tester.tap_button("Continue")
response.assert_contains("Please send your name.")
response = await tester.send_message("Bob")
response.assert_contains("Nice to meet you, Bob!")
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiogram_bot_tester-2.2.0.tar.gz.
File metadata
- Download URL: aiogram_bot_tester-2.2.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abeaf32121ef97eb832b1d3b0e76b7f234021f14ca65b05767bb31354ba3e805
|
|
| MD5 |
9b3394e4fec034a16339c60b25de8357
|
|
| BLAKE2b-256 |
bf5dffb775260c9fbc45f2fd04f4de4c222078c48a3a0428b8126f692d192792
|
File details
Details for the file aiogram_bot_tester-2.2.0-py3-none-any.whl.
File metadata
- Download URL: aiogram_bot_tester-2.2.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d054c2c85d29546355338643ec930f6dee6bc0869b310cde3a73ae12d4d0303
|
|
| MD5 |
239aeceb1de2dfbd5e30ba37438dcc54
|
|
| BLAKE2b-256 |
87de2094ff9812c042f1ccb7de21e9d6c3f67096d376fc5e66a4ead72a2d2f8f
|