diff --git a/src/ophyd_async/core/__init__.py b/src/ophyd_async/core/__init__.py index ee0ef2af2a..9563537339 100644 --- a/src/ophyd_async/core/__init__.py +++ b/src/ophyd_async/core/__init__.py @@ -96,7 +96,6 @@ get_unique, in_micros, wait_for_connection, - wait_for_pending_wakeups, ) __all__ = [ @@ -193,5 +192,4 @@ "in_micros", "wait_for_connection", "completed_status", - "wait_for_pending_wakeups", ] diff --git a/src/ophyd_async/core/_utils.py b/src/ophyd_async/core/_utils.py index 8d3ffe8c35..43ce473b8b 100644 --- a/src/ophyd_async/core/_utils.py +++ b/src/ophyd_async/core/_utils.py @@ -311,24 +311,3 @@ def __call__(self) -> Mock: if self.parent is not None: self.parent().attach_mock(self._mock, self.name) return self._mock - - -async def wait_for_pending_wakeups(max_yields=20, raise_if_exceeded=True): - """Allow any ready asyncio tasks to be woken up. - - Used in: - - - Tests to allow tasks like ``set()`` to start so that signal - puts can be tested - - `observe_value` to allow it to be wrapped in `asyncio.wait_for` - with a timeout - """ - loop = asyncio.get_event_loop() - # If anything has called loop.call_soon or is scheduled a wakeup - # then let it run - for _ in range(max_yields): - await asyncio.sleep(0) - if not loop._ready: # type: ignore # noqa: SLF001 - return - if raise_if_exceeded: - raise RuntimeError(f"Tasks still scheduling wakeups after {max_yields} yields") diff --git a/src/ophyd_async/testing/__init__.py b/src/ophyd_async/testing/__init__.py new file mode 100644 index 0000000000..d3efd849bd --- /dev/null +++ b/src/ophyd_async/testing/__init__.py @@ -0,0 +1,22 @@ +import asyncio + + +async def wait_for_pending_wakeups(max_yields=20, raise_if_exceeded=True): + """Allow any ready asyncio tasks to be woken up. + + Used in: + + - Tests to allow tasks like ``set()`` to start so that signal + puts can be tested + - `observe_value` to allow it to be wrapped in `asyncio.wait_for` + with a timeout + """ + loop = asyncio.get_event_loop() + # If anything has called loop.call_soon or is scheduled a wakeup + # then let it run + for _ in range(max_yields): + await asyncio.sleep(0) + if not loop._ready: # type: ignore # noqa: SLF001 + return + if raise_if_exceeded: + raise RuntimeError(f"Tasks still scheduling wakeups after {max_yields} yields") diff --git a/tests/epics/demo/test_demo.py b/tests/epics/demo/test_demo.py index 640aea8742..fba02106c5 100644 --- a/tests/epics/demo/test_demo.py +++ b/tests/epics/demo/test_demo.py @@ -19,9 +19,9 @@ get_mock, get_mock_put, set_mock_value, - wait_for_pending_wakeups, ) from ophyd_async.epics import demo +from ophyd_async.testing import wait_for_pending_wakeups @pytest.fixture diff --git a/tests/epics/test_motor.py b/tests/epics/test_motor.py index 9960a7a2fa..01f34fd785 100644 --- a/tests/epics/test_motor.py +++ b/tests/epics/test_motor.py @@ -15,9 +15,9 @@ set_mock_put_proceeds, set_mock_value, soft_signal_rw, - wait_for_pending_wakeups, ) from ophyd_async.epics import motor +from ophyd_async.testing import wait_for_pending_wakeups @pytest.fixture