From 16765e5d68325b0be63c510cb4a7d664e4f402e5 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Fri, 16 Oct 2026 16:38:35 +0200 Subject: [PATCH] test: remove collection and deprecation warnings from unit tests --- bec_widgets/tests/testable_qtimer.py | 2 ++ tests/unit_tests/test_atlas_admin_view.py | 2 +- tests/unit_tests/test_device_manager_components.py | 7 ++++--- tests/unit_tests/test_error_utils.py | 8 +++++++- tests/unit_tests/test_generated_form_form.py | 13 +++++++++---- tests/unit_tests/test_heatmap_widget.py | 3 +++ tests/unit_tests/test_modular_toolbar.py | 8 ++++++-- tests/unit_tests/test_property_editor.py | 2 ++ 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/bec_widgets/tests/testable_qtimer.py b/bec_widgets/tests/testable_qtimer.py index 08b4ed1b..87222c0d 100644 --- a/bec_widgets/tests/testable_qtimer.py +++ b/bec_widgets/tests/testable_qtimer.py @@ -17,6 +17,8 @@ class TestableQTimer(QTimer): Patch it over ``qtpy.QtCore.QTimer`` before the widgets under test are imported. """ + __test__ = False # helper class, not a test + _instances: list[tuple[QTimer, str, str]] = [] _current_test_name: str = "" diff --git a/tests/unit_tests/test_atlas_admin_view.py b/tests/unit_tests/test_atlas_admin_view.py index 60521d55..c67a7ead 100644 --- a/tests/unit_tests/test_atlas_admin_view.py +++ b/tests/unit_tests/test_atlas_admin_view.py @@ -256,7 +256,7 @@ class TestBECAtlasHTTPService: def test_handle_response_login(self, http_service, qtbot): """Test that handling a login response correctly decodes the token and starts the auth timer.""" exp = time.time() + 300 - token = jwt.encode({"email": "alice@example.org", "exp": exp}, "secret", algorithm="HS256") + token = jwt.encode({"email": "alice@example.org", "exp": exp}, "x" * 32, algorithm="HS256") payload = ("{" f'"access_token": "{token}"' "}").encode() reply = _FakeReply( request_url="http://localhost:8000/user/login", status=200, payload=payload diff --git a/tests/unit_tests/test_device_manager_components.py b/tests/unit_tests/test_device_manager_components.py index b0d06e54..f9910d1b 100644 --- a/tests/unit_tests/test_device_manager_components.py +++ b/tests/unit_tests/test_device_manager_components.py @@ -13,7 +13,8 @@ from ophyd_devices.interfaces.device_config_templates.ophyd_templates import ( OPHYD_DEVICE_TEMPLATES, EpicsMotorDeviceConfigTemplate, ) -from ophyd_devices.utils.static_device_test import StaticDeviceTest, TestResult +from ophyd_devices.utils.static_device_test import StaticDeviceTest +from ophyd_devices.utils.static_device_test import TestResult as DeviceTestResult from qtpy import QtCore, QtGui, QtWidgets from bec_widgets.tests.client_mocks import mocked_client @@ -1028,7 +1029,7 @@ class TestOphydValidation: runnable.tester, "run_with_list_output" ) as mock_run_with_list_output: mock_run_with_list_output.return_value = [ - TestResult( + DeviceTestResult( name="test_device", config_is_valid=ConfigStatus.VALID.value, success=ConnectionStatus.CANNOT_CONNECT.value, @@ -1445,7 +1446,7 @@ class TestOphydValidation: name = next(iter(tester.config)) started.append(name) release.wait(timeout=3) - return [TestResult(name=name, success=False, message="", config_is_valid=True)] + return [DeviceTestResult(name=name, success=False, message="", config_is_valid=True)] configs = [ {"name": f"dev_{i}", "deviceClass": "ophyd.Signal", "enabled": True} for i in range(6) diff --git a/tests/unit_tests/test_error_utils.py b/tests/unit_tests/test_error_utils.py index f6fb5605..ed56ac44 100644 --- a/tests/unit_tests/test_error_utils.py +++ b/tests/unit_tests/test_error_utils.py @@ -10,6 +10,8 @@ from bec_widgets.utils.error_popups import ErrorPopupUtility, ExampleWidget, Saf class TestSafePropertyClass(QObject): + __test__ = False # helper class, not a test + def __init__(self, parent=None): super().__init__(parent) self._my_value = 10 # internal store @@ -30,6 +32,7 @@ class TestSafePropertyClass(QObject): class TestSafeSlotEmitter(QObject): + __test__ = False # helper class, not a test test_signal = Signal() @@ -38,6 +41,8 @@ class TestSafeSlotClass(QObject): Test class to demonstrate the use of SafeSlot decorator. """ + __test__ = False # helper class, not a test + def __init__(self, parent=None, signal_obj: TestSafeSlotEmitter | None = None): super().__init__(parent) assert signal_obj is not None, "Signal object must be provided" @@ -239,7 +244,8 @@ def test_safe_connect_removes_stale_connection(qtbot): # disconnects itself. A second disconnect attempt must then fail because # the connection no longer exists. emitter.str_signal.emit("after-death") - assert emitter.str_signal.disconnect(wrapper) is False + with pytest.warns(RuntimeWarning, match="Failed to disconnect"): + assert emitter.str_signal.disconnect(wrapper) is False emitter.deleteLater() diff --git a/tests/unit_tests/test_generated_form_form.py b/tests/unit_tests/test_generated_form_form.py index df65f437..a3e8f43f 100644 --- a/tests/unit_tests/test_generated_form_form.py +++ b/tests/unit_tests/test_generated_form_form.py @@ -80,15 +80,20 @@ class GeneratedSignalOnlySchema(BaseModel): class GeneratedScanArgumentSchema(BaseModel): device: Device | str = Field( - default="", **ScanArgument(display_name="Device", description="Device source.").model_dump() + default="", + json_schema_extra=ScanArgument( + display_name="Device", description="Device source." + ).model_dump(), ) signal: Signal | str | None = Field( default=None, - **ScanArgument(display_name="Signal", description="Signal source.").model_dump(), + json_schema_extra=ScanArgument( + display_name="Signal", description="Signal source." + ).model_dump(), ) low_limit: float | None = Field( default=None, - **ScanArgument( + json_schema_extra=ScanArgument( display_name="Low limit", description="Optional lower bound.", reference_units="device", @@ -99,7 +104,7 @@ class GeneratedScanArgumentSchema(BaseModel): ) exposure: float = Field( default=0.1, - **ScanArgument( + json_schema_extra=ScanArgument( display_name="Exposure", tooltip="Camera exposure.", units="s", precision=3, gt=0 ).model_dump(), ) diff --git a/tests/unit_tests/test_heatmap_widget.py b/tests/unit_tests/test_heatmap_widget.py index 6b2cca1d..1b841b9e 100644 --- a/tests/unit_tests/test_heatmap_widget.py +++ b/tests/unit_tests/test_heatmap_widget.py @@ -620,6 +620,8 @@ def test_pending_request_queueing_and_start(heatmap_widget): # Simulate an active worker processing a job so new requests are queued. heatmap_widget._interpolation_worker = mock.MagicMock() heatmap_widget._interpolation_worker.is_processing = True + # Wired like _ensure_interpolation_thread does, so the cleanup disconnect finds it. + heatmap_widget.interpolation_requested.connect(heatmap_widget._interpolation_worker.process) with mock.patch.object(heatmap_widget, "_start_step_scan_interpolation") as start_mock: heatmap_widget._request_step_scan_interpolation( @@ -645,6 +647,7 @@ def test_finish_interpolation_thread_cleans_references(heatmap_widget): thread_mock.isRunning.return_value = True heatmap_widget._interpolation_worker = worker_mock heatmap_widget._interpolation_thread = thread_mock + heatmap_widget.interpolation_requested.connect(worker_mock.process) heatmap_widget._finish_interpolation_thread() diff --git a/tests/unit_tests/test_modular_toolbar.py b/tests/unit_tests/test_modular_toolbar.py index 9f4908a2..ff99e307 100644 --- a/tests/unit_tests/test_modular_toolbar.py +++ b/tests/unit_tests/test_modular_toolbar.py @@ -389,7 +389,9 @@ def test_context_menu_contains_added_actions( toolbar.show_bundles(["test_bundle"]) # Mock the QMenu.exec_ method to prevent the context menu from being displayed and block CI pipeline monkeypatch.setattr(QMenu, "exec_", lambda self, pos=None: None) - event = QContextMenuEvent(QContextMenuEvent.Mouse, QPoint(10, 10)) + event = QContextMenuEvent( + QContextMenuEvent.Reason.Mouse, QPoint(10, 10), toolbar.mapToGlobal(QPoint(10, 10)) + ) toolbar.contextMenuEvent(event) menus = toolbar.findChildren(QMenu) @@ -419,7 +421,9 @@ def test_context_menu_toggle_action_visibility(toolbar_fixture, material_icon_ac # Manually trigger the context menu event monkeypatch.setattr(QMenu, "exec_", lambda self, pos=None: None) - event = QContextMenuEvent(QContextMenuEvent.Mouse, QPoint(10, 10)) + event = QContextMenuEvent( + QContextMenuEvent.Reason.Mouse, QPoint(10, 10), toolbar.mapToGlobal(QPoint(10, 10)) + ) toolbar.contextMenuEvent(event) # Grab the menu that was created diff --git a/tests/unit_tests/test_property_editor.py b/tests/unit_tests/test_property_editor.py index cc601ef4..b1a10974 100644 --- a/tests/unit_tests/test_property_editor.py +++ b/tests/unit_tests/test_property_editor.py @@ -12,6 +12,8 @@ from bec_widgets.utils.property_editor import PropertyEditor class TestWidget(QWidget): """Test widget with various property types for testing the property editor.""" + __test__ = False # helper class, not a test + def __init__(self, parent=None): super().__init__(parent) self.setObjectName("TestWidget")