Registry / testing / pytest-slack

pytest-slack

JSON →
library2.3.1pypypiunverified

pytest-slack is a pytest plugin designed to send test execution reports directly to Slack. While it provided basic reporting, development on this package ceased after version 2.3.1 (December 2020). The project has since been renamed and continued as `pytest-messenger`, which offers broader messaging support including Slack, DingTalk, and Telegram. Users seeking active development and new features should use `pytest-messenger` instead.

pip install pytest-slack
INSTALL
IMPORT
SIG · PYTEST-SLACK
P
pytest-slack
testingpythonv2.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

The plugin is configured via command-line arguments when running `pytest`. It is recommended to use environment variables for sensitive information like Slack webhook URLs, especially in CI/CD environments. Create a test file, then run pytest with the necessary arguments to specify the Slack webhook, channel, and optionally a username.

# Save this in a test file (e.g., test_example.py) def test_passing(): assert True def test_failing(): assert False # To run and report to Slack: # Set your Slack webhook URL as an environment variable or pass directly # Example using environment variable: # export SLACK_HOOK='https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX' # pytest --slack_hook=$SLACK_HOOK --slack_channel='#test-reports' --slack_username='Pytest Bot' # For local testing without environment variables (less secure for CI/CD): # pytest --slack_hook='https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX' --slack_channel='#test-reports' --slack_username='Pytest Bot'
Debug
Known issues
breakingThe `pytest-slack` project has been renamed to `pytest-messenger` starting from version 3.0.0 (on GitHub). This package (`pytest-slack`) is no longer actively maintained, with its last PyPI release (2.3.1) in December 2020. Users should migrate to `pytest-messenger` for continued development and new features.
fix
Migrate your project to use `pytest-messenger`. Uninstall `pytest-slack` and install `pytest-messenger` via `pip uninstall pytest-slack && pip install pytest-messenger`. Update configuration if necessary, as the new package might introduce changes or enhancements.
affects: <=2.3.1
gotchaPassing Slack webhook URLs directly on the command line (`--slack_hook`) can expose sensitive credentials in logs or command history. This is particularly risky in CI/CD pipelines.
fix
Always use environment variables for sensitive information like `SLACK_HOOK` when running `pytest`. For example, `export SLACK_HOOK="your_webhook_url"` and then use `pytest --slack_hook=$SLACK_HOOK` or configure `pytest.ini` to read from environment variables if supported (check `pytest-messenger` documentation for current best practices).
affects: *
gotchaWhen running tests in parallel with `pytest-xdist`, using the `pytest_sessionfinish` hook in `conftest.py` for Slack reporting can result in multiple messages being sent (one from each worker process).
fix
To ensure a single consolidated report, switch to using the `pytest_terminal_summary` hook in your `conftest.py` file instead of `pytest_sessionfinish`. This hook is executed once, after the entire test run finishes.
affects: *
Errors
Common errors & fixes
Tests run but no report sent to Slack.
The configured Slack webhook URL is incorrect, inaccessible, or there's a network issue preventing the plugin from reaching Slack's API.
fix
Verify the `--slack_hook` value for typos, ensure it's a valid Slack Incoming Webhook URL, and check network connectivity from the environment where `pytest` is executed. Also, ensure the Slack channel exists and the webhook has permissions to post to it.
ERROR: [Errno 111] Connection refused (or similar network error)
The system running `pytest-slack` cannot establish a network connection to the Slack API endpoint, possibly due to firewall rules, proxy issues, or a temporary outage.
fix
Check local firewall settings, ensure any necessary proxy configurations are correctly set in the environment, and confirm that Slack's API is reachable (e.g., `curl -v <slack_webhook_url>`).
Received multiple messages on the Slack channel when running tests with `pytest-xdist`.
The `pytest_sessionfinish` hook, which might be implicitly or explicitly used for reporting, is executed by each parallel worker process of `pytest-xdist`.
fix
Implement reporting logic within the `pytest_terminal_summary` hook in your `conftest.py`. This hook runs only once after all test workers have completed their execution, allowing for a single aggregated report.
Upgrade
Version history
2.3.1latest on PyPI · released Dec 15, 2020
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the Slack API.
pytestrequiredCore testing framework that this plugin extends.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
pytest-slack — pip install pytest-slack · libregistry