Skip to content

Commit

Permalink
added better error message and test
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Feb 15, 2024
1 parent 925ada2 commit 084ddda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ophyd_async/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,12 @@ async def __aexit__(self, type, value, traceback):

def __exit__(self, type_, value, traceback):
self._objects_on_exit = self._caller_locals()
return call_in_bluesky_event_loop(self._on_exit())
try:
fut = call_in_bluesky_event_loop(self._on_exit())
except RuntimeError:
raise NotConnected(
"Could not connect devices. Is the bluesky event loop running? See "
"https://blueskyproject.io/ophyd-async/main/"
"user/explanations/event-loop-choice.html for more info."
)
return fut
11 changes: 11 additions & 0 deletions tests/core/test_device_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ def test_device_collector_does_not_propagate_error(RE):
_ = Dummy("somename")

assert not exc.value.__cause__


async def test_device_connector_sync_no_run_engine_raises_error():
with pytest.raises(NotConnected) as e:
with DeviceCollector():
_ = Dummy("somename")
assert e.value.lines == [
"Could not connect devices. Is the bluesky event loop running? See "
"https://blueskyproject.io/ophyd-async/main/"
"user/explanations/event-loop-choice.html for more info."
]

0 comments on commit 084ddda

Please sign in to comment.