Registry / testing / pytest-messenger

pytest-messenger

JSON →
library3.3.0pypypiunverified

pytest-messenger is a pytest plugin for sending test execution reports to various instant messaging platforms, including Slack, DingTalk, and Telegram. It streamlines communication for CI/CD pipelines and development teams by providing automated notifications of test outcomes. The library is actively maintained, with the current version being 3.3.0, and receives updates periodically.

pip install pytest-messenger
INSTALL
IMPORT
SIG · PYTEST-MESSENGER
P
pytest-messenger
testingpythonv3.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

To quickly get started with pytest-messenger, you typically configure it via command-line options or a `pytest.ini` file. This example demonstrates how to run pytest and report results to Slack using environment variables for sensitive data. Ensure your Slack webhook URL is correctly configured and accessible.

import os import pytest # To simulate a test run and trigger reporting def test_example_success(): assert True def test_example_failure(): assert False # To run this example: # 1. Create a virtual environment and install pytest-messenger: # pip install pytest-messenger pytest # 2. Set your Slack webhook URL as an environment variable: # export SLACK_WEBHOOK_URL='https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' # 3. (Optional) Set a Slack channel and username: # export SLACK_CHANNEL='#test-reports' # export SLACK_USERNAME='CI Bot' # 4. Save the above Python code as a test file (e.g., test_report.py). # 5. Run pytest with the plugin options (values are pulled from env vars): # pytest test_report.py \ # --slack_hook="${SLACK_WEBHOOK_URL}" \ # --slack_channel="${SLACK_CHANNEL:-#general}" \ # --slack_username="${SLACK_USERNAME:-Pytest Report}"
Debug
Known issues
breakingIn version 3.0.0, the package was renamed from `pytest-slack` to `pytest-messenger` to reflect support for multiple messaging platforms (Slack, DingTalk, Telegram). If upgrading from an older version (pre-3.0.0) that used `pytest-slack`, you must uninstall the old package and install `pytest-messenger`. Command-line arguments and configuration options might also have minor changes.
fix
Uninstall `pytest-slack` (if present) and `pip install pytest-messenger`. Review the new documentation for specific command-line argument and `pytest.ini` key changes if you encounter issues.
affects: <3.0.0
gotchaSensitive information like webhook URLs and API tokens should not be hardcoded in your test files or version-controlled configuration files. Always use environment variables, a secrets management system, or a `pytest.ini` file with appropriate access controls.
fix
Pass sensitive data via environment variables (e.g., `os.environ.get('SLACK_WEBHOOK_URL')`) and reference them in your `pytest` command or `pytest.ini` configuration. For example, `--slack_hook='${SLACK_WEBHOOK_URL}'`.
affects: All
gotchaIf reports are not being sent, check that the provided webhook URL or API token (for Slack, DingTalk, Telegram) is correct and has the necessary permissions in your messenger application. Incorrect credentials often lead to silent failures where no report is posted.
fix
Verify the webhook URL/token directly with your messenger platform's integration settings. Ensure it's active and correctly copied. Check the pytest output for any plugin-specific error messages that might indicate an issue with the API call.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'slack_sdk'
The user installed `pytest-messenger` but did not install its optional dependency required for Slack messaging.
fix
Install `pytest-messenger` with the Slack extra: `pip install pytest-messenger[slack]`.
pytest_messenger.messenger.exceptions.MessengerError: Failed to send message: 401 Client Error: Unauthorized for url:
The provided API token (e.g., Slack bot token, Telegram bot token) is invalid, expired, or lacks the necessary permissions, or the channel/chat ID is incorrect.
fix
Verify that the API token and target channel/chat ID are correct, active, and have the required permissions configured in the respective messaging platform.
pytest-messenger slack not sending messages
The specific messenger (e.g., Slack, Telegram) was not activated via command-line options or correctly configured in `pytest.ini` to be active.
fix
Ensure you activate the desired messenger using the appropriate command-line flag (e.g., `pytest --messenger-slack`) or set `messenger_slack = True` in your `pytest.ini` under the `[pytest]` section.
Upgrade
Version history
3.3.0latest on PyPI · released Nov 24, 2022
Audit
Dependencies
pytestrequiredCore testing framework that this plugin extends.
requestsrequiredUsed for making HTTP requests to messenger APIs (e.g., Slack webhooks, Telegram Bot API).
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
pytest-messenger — pip install pytest-messenger · libregistry