Skip to content

Commit 99f216f

Browse files
committed
Switched to using 'mocker' within test function instead of stacking multiple 'mock.patch' decorators
1 parent 5993c23 commit 99f216f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tests/instrument_server/test_api.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,22 @@ def test_check_multigrid_controller_exists(mocker: MockerFixture):
9999

100100

101101
@pytest.mark.parametrize("test_params", test_upload_gain_reference_params_matrix)
102-
@patch("murfey.instrument_server.api.subprocess")
103-
@patch("murfey.instrument_server.api.tokens")
104-
@patch("murfey.instrument_server.api._get_murfey_url")
105-
@patch("murfey.instrument_server.api.requests")
106102
def test_upload_gain_reference(
107-
mock_request,
108-
mock_get_server_url,
109-
mock_tokens,
110-
mock_subprocess,
103+
mocker: MockerFixture,
111104
test_params: tuple[Optional[str]],
112105
):
113-
114106
# Unpack test parameters and define other ones
115107
(rsync_url_setting,) = test_params
116108
server_url = "http://0.0.0.0:8000"
117109
instrument_name = "murfey"
118110
session_id = 1
119111

112+
# Mock out objects
113+
mock_request = mocker.patch("murfey.instrument_server.api.requests")
114+
mock_get_server_url = mocker.patch("murfey.instrument_server.api._get_murfey_url")
115+
mock_subprocess = mocker.patch("murfey.instrument_server.api.subprocess")
116+
mocker.patch("murfey.instrument_server.api.tokens", {session_id: ANY})
117+
120118
# Create a mock machine config base on the test params
121119
rsync_module = "data"
122120
gain_ref_dir = "C:/ProgramData/Gatan/Gain Reference"

0 commit comments

Comments
 (0)