{"id":9251,"library":"pytest-slack","title":"Pytest Slack Reporting Plugin","description":"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.","status":"abandoned","version":"2.3.1","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-slack","tags":["pytest-plugin","slack","testing","reporting","ci/cd"],"install":[{"cmd":"pip install pytest-slack","lang":"bash","label":"Install latest PyPI version"}],"dependencies":[{"reason":"Used for making HTTP requests to the Slack API.","package":"requests","optional":false},{"reason":"Core testing framework that this plugin extends.","package":"pytest","optional":false}],"imports":[],"quickstart":{"code":"# Save this in a test file (e.g., test_example.py)\ndef test_passing():\n    assert True\n\ndef test_failing():\n    assert False\n\n# To run and report to Slack:\n# Set your Slack webhook URL as an environment variable or pass directly\n# Example using environment variable:\n# export SLACK_HOOK='https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX'\n# pytest --slack_hook=$SLACK_HOOK --slack_channel='#test-reports' --slack_username='Pytest Bot'\n# For local testing without environment variables (less secure for CI/CD):\n# pytest --slack_hook='https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX' --slack_channel='#test-reports' --slack_username='Pytest Bot'","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":"<=2.3.1"},{"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).","message":"Passing 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.","severity":"gotcha","affected_versions":"*"},{"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.","message":"When 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).","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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.","cause":"The configured Slack webhook URL is incorrect, inaccessible, or there's a network issue preventing the plugin from reaching Slack's API.","error":"Tests run but no report sent to Slack."},{"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>`).","cause":"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.","error":"ERROR: [Errno 111] Connection refused (or similar network error)"},{"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.","cause":"The `pytest_sessionfinish` hook, which might be implicitly or explicitly used for reporting, is executed by each parallel worker process of `pytest-xdist`.","error":"Received multiple messages on the Slack channel when running tests with `pytest-xdist`."}]}