|
1 | 1 | """Tests for keras_remote.runner.remote_runner — GCS helpers and execution.""" |
2 | 2 |
|
3 | 3 | import os |
4 | | -import pickle |
| 4 | +import sys |
5 | 5 |
|
6 | 6 | import cloudpickle |
7 | 7 | import pytest |
@@ -65,6 +65,11 @@ def test_parses_gcs_path(self, mocker): |
65 | 65 |
|
66 | 66 |
|
67 | 67 | 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 | + |
68 | 73 | def test_success_flow(self, mocker, tmp_path): |
69 | 74 | """Verify successful function execution: download, execute, upload result.""" |
70 | 75 | src_dir = tmp_path / "src" |
@@ -139,7 +144,7 @@ def fake_download(client, gcs_path, local_path): |
139 | 144 | # Verify result payload |
140 | 145 | result_path = upload_args[1] |
141 | 146 | with open(result_path, "rb") as f: |
142 | | - result_payload = pickle.load(f) |
| 147 | + result_payload = cloudpickle.load(f) |
143 | 148 | assert result_payload["success"] is True |
144 | 149 | assert result_payload["result"] == 5 |
145 | 150 |
|
@@ -210,7 +215,7 @@ def fake_download(client, gcs_path, local_path): |
210 | 215 | # Verify result payload has the exception |
211 | 216 | result_path = mock_upload.call_args[0][1] |
212 | 217 | with open(result_path, "rb") as f: |
213 | | - result_payload = pickle.load(f) |
| 218 | + result_payload = cloudpickle.load(f) |
214 | 219 | assert result_payload["success"] is False |
215 | 220 | assert isinstance(result_payload["exception"], ValueError) |
216 | 221 | assert "test error" in str(result_payload["exception"]) |
@@ -286,7 +291,7 @@ def fake_download(client, gcs_path, local_path): |
286 | 291 |
|
287 | 292 | result_path = mock_upload.call_args[0][1] |
288 | 293 | with open(result_path, "rb") as f: |
289 | | - result_payload = pickle.load(f) |
| 294 | + result_payload = cloudpickle.load(f) |
290 | 295 | assert result_payload["success"] is True |
291 | 296 | assert result_payload["result"] == "hello" |
292 | 297 |
|
|
0 commit comments