Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Bibo-Joshi edited this pageJan 7, 2024 ·21 revisions

In case you want to practicetest-driven development, or ensure your bot still works after consecutive changes (regression bugs are rather common for chatbots), you should write test cases.

Unit Tests

Unit tests are performed on a logically encapsulated component of the system. The definition of unit tests in contrast to integration tests is that they have no external dependencies.

Thanks to PTBs modular structure, integration with unit tests can already be achieved for many use cases without additional tooling. For example, you can

  • manually enqueue updates in theApplication.update_queue or directly callApplication.process_update. This allows you to check that verify that updates are being processed as desiderd without fetching any data from Telegram. Note that for this approach, you'll probably want to setthe updater toNone
  • mock the networking connection to Telegram, i.e. instead of sending the API requests to Telegram you send them to a fictional backend that you control yourself. That way, your tests can not be corrupted by networking issues and do not need an internet connection. This can be achieved e.g. by subclassing theBot class and overriding all methods or by implementing a subclass ofBaseRequest.

Moreover, @Eldinnie has written an initial POC of a unit test framework for python-telegram-bot, but as the library grew it was not maintained. Perhaps you might be able to help us out here and help in completing the project ;)https://github.com/Eldinnie/ptbtest

Integration Tests

In contrast to unit tests, integration tests may test the system in its eventual environment together with service integrations, such as the Bot API.

In order to test your bot in a real environment, you can make use of auserbot library that will send messages to your bot and evaluate whether it responds in the way it should.Telethon orPyrogram should be the choices in a Python environment.The currently unmaintainedTgIntegration library was written for exactly this purpose, so maybe someone could come along with a pull request to update it to the latest version of Pyrogram.

Wiki ofpython-telegram-bot © Copyright 2015-2025 – Licensed byCreative Commons

Must read

  1. Introduction to the API
  2. Tutorial: Your first bot
  3. FAQ
  4. How to ask good questions
  5. How to write an MWE

Concepts & Important Elements

  1. Architecture Overview
  2. Builder Pattern forApplication
  3. Types of Handlers
  4. Working with Files and Media
  5. Exceptions, Warnings and Logging
  6. Concurrency in PTB

Notable Features

  1. Advanced Filters
  2. Storing data
  3. Making your bot persistent
  4. Adding Defaults
  5. Job Queue
  6. Arbitrarycallback_data
  7. Avoiding flood limits
  8. Webhooks
  9. Bot API Forward Compatiblity

Code Resources

  1. Frequently requested design patterns
  2. Code snippets
  3. Performance Optimizations
  4. Telegram Passport
  5. Bots built with PTB
  6. Automated Bot Tests

Examples explained

  1. InlineKeyboard Example

Networking

  1. Working Behind a Proxy
  2. Handling network errors

Other resources

  1. Where to host Telegram Bots
  2. How to host your bot
  3. Local API Server
  4. Type Checking with PTB
  5. Press
  6. Notes on GAE
  7. Related Projects
  8. Emoji

Transition Guides

Administration

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp