Skip to content

Commit 70d9e87

Browse files
committed
fix: pytests
1 parent 7845eca commit 70d9e87

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

services/staging/rs_server_staging/processors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""RSPY Staging processor."""
1515

1616
import asyncio # for handling asynchronous tasks
17-
import json
1817
import os
1918
import time
2019
import uuid
@@ -705,7 +704,7 @@ def dask_cluster_connect(self) -> Client: # pylint: disable=too-many-branches,t
705704

706705
# Sort the clusters by newest first
707706
clusters = sorted(gateway.list_clusters(), key=lambda cluster: cluster.start_time, reverse=True)
708-
self.logger.debug(f"Cluster list for gateway {os.environ['DASK_GATEWAY__ADDRESS']!r}:{clusters}")
707+
self.logger.debug(f"Cluster list for gateway {os.environ['DASK_GATEWAY__ADDRESS']!r}: {clusters}")
709708

710709
# In local mode, get the first cluster from the gateway.
711710
cluster_id = None

services/staging/tests/test_rspy_processor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ def test_dask_cluster_connect(self, mocker, staging_instance: Staging, cluster_o
715715
"RSPY_DASK_STAGING_CLUSTER_NAME": cluster_options["cluster_name"],
716716
},
717717
)
718+
# Mock the cluster mode
719+
mocker.patch("rs_server_staging.processors.LOCAL_MODE", new=False, autospec=False)
718720
# Mock the logger
719721
mock_logger = mocker.patch.object(staging_instance, "logger")
720722
staging_instance.cluster = None
@@ -749,7 +751,9 @@ def test_dask_cluster_connect(self, mocker, staging_instance: Staging, cluster_o
749751
mock_client.assert_called_once_with(staging_instance.cluster)
750752

751753
# Ensure logging was called as expected
752-
mock_logger.debug.assert_any_call(f"The list of clusters: {mock_list_clusters.return_value}")
754+
mock_logger.debug.assert_any_call(
755+
f"Cluster list for gateway 'gateway-address': {mock_list_clusters.return_value}",
756+
)
753757
mock_logger.info.assert_any_call("Number of running workers: 2")
754758
mock_logger.debug.assert_any_call(
755759
f"Dask Client: {client} | Cluster dashboard: {mock_connect.return_value.dashboard_link}",
@@ -768,6 +772,8 @@ def test_dask_cluster_connect_failure_no_cluster_name(self, mocker, staging_inst
768772
"RSPY_DASK_STAGING_CLUSTER_NAME": non_existent_cluster,
769773
},
770774
)
775+
# Mock the cluster mode
776+
mocker.patch("rs_server_staging.processors.LOCAL_MODE", new=False, autospec=False)
771777
# Mock the logger
772778
mock_logger = mocker.patch.object(staging_instance, "logger")
773779
staging_instance.cluster = None
@@ -791,7 +797,8 @@ def test_dask_cluster_connect_failure_no_cluster_name(self, mocker, staging_inst
791797
staging_instance.dask_cluster_connect()
792798
# Ensure logging was called as expected
793799
mock_logger.exception.assert_any_call(
794-
"Failed to find the specified dask cluster: " f"No dask cluster named '{non_existent_cluster}' was found.",
800+
"Failed to find the specified dask cluster: "
801+
f"Dask cluster with 'cluster_name'={non_existent_cluster!r} was not found.",
795802
)
796803

797804
def test_dask_cluster_connect_failure_no_envs(self, mocker, staging_instance: Staging):

services/staging/tests/test_staging.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,7 @@ async def test_app_lifespan_gateway_error(
526526
"""Test app_lifespan when there is an error in connecting to the Dask Gateway."""
527527

528528
# Mock environment variables to simulate gateway mode
529-
mocker.patch.dict(
530-
os.environ,
531-
{
532-
"RSPY_LOCAL_MODE": "0",
533-
},
534-
)
529+
mocker.patch("rs_server_staging.main.LOCAL_MODE", new=False, autospec=False)
535530

536531
# Mock FastAPI app
537532
mock_app = FastAPI()

0 commit comments

Comments
 (0)