Skip to content

Commit a7c7deb

Browse files
committed
Fixed broken test
1 parent f001b9c commit a7c7deb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/instrument_server/test_init.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import logging
12
import sys
23
from typing import Optional
4+
from unittest.mock import MagicMock
35
from urllib.parse import urlparse
46

57
import pytest
@@ -14,6 +16,7 @@
1416
from murfey.instrument_server import check_for_updates, start_instrument_server
1517
from murfey.server.api.bootstrap import pypi as pypi_router, version as version_router
1618
from murfey.util.api import url_path_for
19+
from murfey.util.logging import HTTPSHandler
1720

1821
# Set up a test router with only the essential endpoints
1922
app = FastAPI()
@@ -132,11 +135,28 @@ def test_check_for_updates(
132135

133136
@pytest.mark.parametrize("test_params", start_instrument_server_test_matrix)
134137
def test_start_instrument_server(
135-
mocker: MockerFixture, test_params: tuple[Optional[str], Optional[int]]
138+
mocker: MockerFixture,
139+
mock_client_configuration,
140+
test_params: tuple[Optional[str], Optional[int]],
136141
):
137142
# Unpack test params
138143
host, port = test_params
139144

145+
# Patch the 'read_config' function
146+
_ = mocker.patch(
147+
"murfey.util.client.read_config", return_value=mock_client_configuration
148+
)
149+
150+
# Mock the HTTPSHandler (test it separately in a unit test)
151+
mock_https_handler_instance = MagicMock()
152+
mock_https_handler_instance.level = logging.INFO
153+
mock_https_handler_instance.setLevel.return_value = None
154+
mock_https_handler = mocker.patch(
155+
"murfey.util.logging.HTTPSHandler",
156+
spec=HTTPSHandler,
157+
)
158+
mock_https_handler.return_value = mock_https_handler_instance
159+
140160
# Patch the Uvicorn Server instance
141161
mock_server = mocker.patch("uvicorn.Server")
142162
# Disable 'run'; we just want to confirm it's called correctly

0 commit comments

Comments
 (0)