Skip to content

Commit df258fe

Browse files
address reviews
1 parent fc84d33 commit df258fe

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

keras_remote/runner/test_remote_runner.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for keras_remote.runner.remote_runner — GCS helpers and execution."""
22

33
import os
4-
import pickle
4+
import sys
55

66
import cloudpickle
77
import pytest
@@ -65,6 +65,11 @@ def test_parses_gcs_path(self, mocker):
6565

6666

6767
class TestRunGcsMode:
68+
@pytest.fixture(autouse=True)
69+
def _protect_sys_path(self, monkeypatch):
70+
"""Prevent run_gcs_mode's sys.path.insert from leaking across tests."""
71+
monkeypatch.setattr(sys, "path", sys.path[:])
72+
6873
def test_success_flow(self, mocker, tmp_path):
6974
"""Verify successful function execution: download, execute, upload result."""
7075
src_dir = tmp_path / "src"
@@ -139,7 +144,7 @@ def fake_download(client, gcs_path, local_path):
139144
# Verify result payload
140145
result_path = upload_args[1]
141146
with open(result_path, "rb") as f:
142-
result_payload = pickle.load(f)
147+
result_payload = cloudpickle.load(f)
143148
assert result_payload["success"] is True
144149
assert result_payload["result"] == 5
145150

@@ -210,7 +215,7 @@ def fake_download(client, gcs_path, local_path):
210215
# Verify result payload has the exception
211216
result_path = mock_upload.call_args[0][1]
212217
with open(result_path, "rb") as f:
213-
result_payload = pickle.load(f)
218+
result_payload = cloudpickle.load(f)
214219
assert result_payload["success"] is False
215220
assert isinstance(result_payload["exception"], ValueError)
216221
assert "test error" in str(result_payload["exception"])
@@ -286,7 +291,7 @@ def fake_download(client, gcs_path, local_path):
286291

287292
result_path = mock_upload.call_args[0][1]
288293
with open(result_path, "rb") as f:
289-
result_payload = pickle.load(f)
294+
result_payload = cloudpickle.load(f)
290295
assert result_payload["success"] is True
291296
assert result_payload["result"] == "hello"
292297

0 commit comments

Comments
 (0)