Pytest Messenger

3.3.0 · active · verified Sat Apr 11

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.

Warnings

Install

Quickstart

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}"

view raw JSON →