From 099290c86849faf31cbc4369123b7a6abf246446 Mon Sep 17 00:00:00 2001 From: Hiran Wijesinghe Date: Fri, 14 Nov 2025 13:15:05 +0000 Subject: [PATCH 1/2] fix locally runnable tests --- pyproject.toml | 2 +- tests/conftest.py | 9 +++++++++ tests/test_launch.py | 8 ++++++++ tests/transport/tango/test_dsr.py | 8 +++++--- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a6ccbc4d6..e2e962719 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,7 +91,7 @@ addopts = """ """ # https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings # https://github.com/DiamondLightSource/FastCS/issues/230 -# filterwarnings = "error" +filterwarnings = "error" # Doctest python code in docs, python code in src docstrings, test functions in tests testpaths = "docs src tests" timeout = 1 diff --git a/tests/conftest.py b/tests/conftest.py index f6770d5e9..21373247e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import asyncio import io import multiprocessing import os @@ -236,3 +237,11 @@ def test_controller(tango_system, register_device): process.send_signal(signal.SIGINT) process.wait(timeout) + + +@pytest.fixture +def event_loop(): + loop = asyncio.new_event_loop() + yield loop + loop.run_until_complete(loop.shutdown_asyncgens()) + loop.close() diff --git a/tests/test_launch.py b/tests/test_launch.py index 36c505280..883fcdb9c 100644 --- a/tests/test_launch.py +++ b/tests/test_launch.py @@ -154,6 +154,14 @@ def test_error_if_identical_context_in_transports(mocker: MockerFixture, data): new_callable=mocker.PropertyMock, return_value={"controller": "test"}, ) + mocker.patch( + "fastcs.transport.epics.pva.transport.EpicsPVATransport.serve", + new_callable=mocker.PropertyMock, + ) + mocker.patch( + "fastcs.transport.epics.ca.transport.EpicsCATransport.serve", + new_callable=mocker.PropertyMock, + ) app = _launch(IsHinted) result = runner.invoke(app, ["run", str(data / "config.yaml")]) assert isinstance(result.exception, RuntimeError) diff --git a/tests/transport/tango/test_dsr.py b/tests/transport/tango/test_dsr.py index 4883601f9..4baf91ad7 100644 --- a/tests/transport/tango/test_dsr.py +++ b/tests/transport/tango/test_dsr.py @@ -50,9 +50,11 @@ def create_test_context(tango_controller_api: AssertableControllerAPI): tango_transport = TangoTransport() tango_transport.connect( tango_controller_api, - # This is passed to enable instantiating the transport, but tests must avoid - # using via patching of functions. It will raise NotImplementedError if used. - asyncio.AbstractEventLoop(), + # changed from asyncio.AbstractEventLoop since TangoTransport ends up holding + # a non-functional loop, while the actual event loop used by DeviceTestContext + # is created internally by PyTango and never closed, along with open sockets! + # This event loop is now correctly closed by event_loop ficture in conftest. + asyncio.get_event_loop(), ) device = tango_transport._dsr._device # https://tango-controls.readthedocs.io/projects/pytango/en/v9.5.1/testing/test_context.html From 42bcb3d38265e1571be9918fe25af3de9facab0c Mon Sep 17 00:00:00 2001 From: Hiran Wijesinghe Date: Fri, 14 Nov 2025 14:35:05 +0000 Subject: [PATCH 2/2] removed comment as code is self-explanatory --- tests/transport/tango/test_dsr.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/transport/tango/test_dsr.py b/tests/transport/tango/test_dsr.py index 4baf91ad7..449732853 100644 --- a/tests/transport/tango/test_dsr.py +++ b/tests/transport/tango/test_dsr.py @@ -50,10 +50,6 @@ def create_test_context(tango_controller_api: AssertableControllerAPI): tango_transport = TangoTransport() tango_transport.connect( tango_controller_api, - # changed from asyncio.AbstractEventLoop since TangoTransport ends up holding - # a non-functional loop, while the actual event loop used by DeviceTestContext - # is created internally by PyTango and never closed, along with open sockets! - # This event loop is now correctly closed by event_loop ficture in conftest. asyncio.get_event_loop(), ) device = tango_transport._dsr._device