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-slackNo compatibility data collected yet for this library.
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.
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.
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).
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.
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.
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>`).
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.