Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sdgym/run_benchmark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import numpy as np
import pandas as pd
from scipy.interpolate import interp1d
from slack_sdk import WebClient

from sdgym.s3 import parse_s3_path

try:
from slack_sdk import WebClient
except ImportError: # Slack is only needed to post benchmark notifications
WebClient = None

OUTPUT_DESTINATION_AWS = 's3://sdgym-benchmark/Benchmarks/'
DEBUG_SLACK_CHANNEL = 'sdv-alerts-debug'
SLACK_CHANNEL = 'sdgym'
Expand Down Expand Up @@ -84,6 +88,12 @@ def _get_slack_client():
WebClient:
An authenticated Slack WebClient instance.
"""
if WebClient is None:
raise ImportError(
"Posting Slack messages requires the 'slack-sdk' package. "
"Install it with 'pip install slack-sdk'."
)

token = os.getenv('SLACK_TOKEN')
client = WebClient(token=token)
return client
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/run_benchmark/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def test_get_slack_client(mock_getenv, mock_web_client):
assert client is mock_web_client.return_value


@patch('sdgym.run_benchmark.utils.WebClient', None)
def test_get_slack_client_without_slack_sdk():
"""Test `_get_slack_client` raises a clear error when `slack_sdk` is not installed."""
# Run and Assert
with pytest.raises(ImportError, match='slack-sdk'):
_get_slack_client()


@patch('sdgym.run_benchmark.utils._get_slack_client')
def test_post_slack_message(mock_get_slack_client):
"""Test the `post_slack_message` method."""
Expand Down