From d673ceab7b9df316dbbef1f137134755870d4582 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 3 Mar 2026 15:13:54 +0000 Subject: [PATCH] Update test suite to cope with LabThings validating properties on write (https://github.com/labthings/labthings-fastapi/pull/278) --- tests/unit_tests/test_simulated_camera.py | 3 ++- tests/unit_tests/test_smart_scan.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_simulated_camera.py b/tests/unit_tests/test_simulated_camera.py index 4935d9d6..dd499fc9 100644 --- a/tests/unit_tests/test_simulated_camera.py +++ b/tests/unit_tests/test_simulated_camera.py @@ -7,6 +7,7 @@ import numpy as np import pytest from hypothesis import given from hypothesis import strategies as st +from pydantic import ValidationError import labthings_fastapi as lt @@ -210,7 +211,7 @@ def test_objective_getter_setter(camera): camera.objective = 15 with pytest.raises(ValueError, match=err_msg): camera.objective = 0 - with pytest.raises(ValueError, match=err_msg): + with pytest.raises(ValidationError): camera.objective = "twenty" diff --git a/tests/unit_tests/test_smart_scan.py b/tests/unit_tests/test_smart_scan.py index e8abf2d5..566faea9 100644 --- a/tests/unit_tests/test_smart_scan.py +++ b/tests/unit_tests/test_smart_scan.py @@ -25,7 +25,7 @@ from unittest import mock import pytest from fastapi import HTTPException -from pydantic import BaseModel +from pydantic import BaseModel, ValidationError from labthings_fastapi.exceptions import InvocationCancelledError from labthings_fastapi.testing import create_thing_without_server @@ -206,8 +206,11 @@ def test_setting_workflows(caplog, mocker): with caplog.at_level(logging.WARNING), smart_scan_thing: assert smart_scan_thing._workflow_name == "foo" assert smart_scan_thing._workflow is workflows["foo"] - # Can't set None, warns doesn't change - smart_scan_thing.workflow_name = None + # Can't set None, raises a ValidationError + with pytest.raises(ValidationError): + smart_scan_thing.workflow_name = None + # Empty string still won't change, but just warns + smart_scan_thing.workflow_name = "" assert len(caplog.records) == 1 assert smart_scan_thing._workflow_name == "foo" assert smart_scan_thing._workflow is workflows["foo"]