From 6a8e1198d9c3a8bf6eeb537b4f28b63292f5ca0f Mon Sep 17 00:00:00 2001 From: Beth Probert Date: Wed, 4 Mar 2026 18:16:22 +0000 Subject: [PATCH] Add unit test for debug cli arg --- tests/unit_tests/test_server_cli.py | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/unit_tests/test_server_cli.py b/tests/unit_tests/test_server_cli.py index 7901fc69..06102e3c 100644 --- a/tests/unit_tests/test_server_cli.py +++ b/tests/unit_tests/test_server_cli.py @@ -103,3 +103,34 @@ def test_failed_customise(mocker): assert isinstance(fallback_app, FastAPI) # An that it has the error to display assert str(fallback_app._context.error) == "Can't touch this" + + +def test_debug_mode(mocker): + """Test that --debug flag triggers lt.logs.configure_thing_logger.""" + # Mock the LabThings function that returns the server + mocker.patch( + "openflexure_microscope_server.server.lt.ThingServer.from_config", + return_value=mocker.Mock(), + ) + # Mock customisation to avoid side effects + mocker.patch.object(ofm_server, "customise_server") + # Mock uvicorn.run to avoid starting a server + mocker.patch("openflexure_microscope_server.server.uvicorn.run") + + # Mock the target function + mock_configure_thing_logger = mocker.patch( + "openflexure_microscope_server.server.lt.logs.configure_thing_logger" + ) + + # 1. Run with --debug + ofm_server.serve_from_cli(["-c", SIM_CONFIG, "--debug"]) + + # Verify it was called with DEBUG level + mock_configure_thing_logger.assert_called_once_with(logging.DEBUG) + + # 2. Run without --debug + mock_configure_thing_logger.reset_mock() + ofm_server.serve_from_cli(["-c", SIM_CONFIG]) + + # Verify it was NOT called + mock_configure_thing_logger.assert_not_called()