Skip to content

Commit 0f54c1c

Browse files
committed
fix access to Process, create mock objects explicitly
1 parent f853296 commit 0f54c1c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

jupyter_scheduler/tests/test_job_files_manager.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import tarfile
55
import time
66
from pathlib import Path
7-
from unittest.mock import patch
7+
from unittest.mock import patch, MagicMock
88

99
import pytest
1010

@@ -40,13 +40,20 @@ async def test_copy_from_staging():
4040
"input": "helloworld.ipynb",
4141
}
4242
output_dir = "jobs/1"
43+
44+
mock_scheduler = MagicMock()
45+
mock_scheduler.get_job.return_value = job
46+
mock_scheduler.get_staging_paths.return_value = staging_paths
47+
mock_scheduler.get_local_output_path.return_value = output_dir
48+
mock_scheduler.get_job_filenames.return_value = job_filenames
49+
50+
mock_context = MagicMock()
51+
mock_process = MagicMock()
52+
mock_context.Process.return_value = mock_process
53+
4354
with patch("jupyter_scheduler.job_files_manager.Downloader") as mock_downloader:
44-
with patch("jupyter_scheduler.job_files_manager.Process") as mock_process:
45-
with patch("jupyter_scheduler.scheduler.Scheduler") as mock_scheduler:
46-
mock_scheduler.get_job.return_value = job
47-
mock_scheduler.get_staging_paths.return_value = staging_paths
48-
mock_scheduler.get_local_output_path.return_value = output_dir
49-
mock_scheduler.get_job_filenames.return_value = job_filenames
55+
with patch("jupyter_scheduler.scheduler.Scheduler", return_value=mock_scheduler):
56+
with patch("multiprocessing.get_context", return_value=mock_context):
5057
manager = JobFilesManager(scheduler=mock_scheduler)
5158
await manager.copy_from_staging(1)
5259

@@ -58,6 +65,7 @@ async def test_copy_from_staging():
5865
redownload=False,
5966
include_staging_files=None,
6067
)
68+
mock_process.start.assert_called_once()
6169

6270

6371
HERE = Path(__file__).parent.resolve()

0 commit comments

Comments
 (0)