Start a bluesky event loop at the start of a test session#1492
Start a bluesky event loop at the start of a test session#1492DominicOram merged 6 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1492 +/- ##
=======================================
Coverage 98.75% 98.75%
=======================================
Files 235 235
Lines 8642 8645 +3
=======================================
+ Hits 8534 8537 +3
Misses 108 108 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
olliesilvester
left a comment
There was a problem hiding this comment.
Looks good, thanks. I haven't thoroughly checked to see if every RE was removed from the tests, but it looks like you got most of them
| @pytest.fixture | ||
| async def RE(): | ||
| @pytest.fixture(scope="session", autouse=True) | ||
| async def _ensure_running_bluesky_event_loop(): |
There was a problem hiding this comment.
I don't know if it's doable with the current tests, but I think the relationship between these fixtures should be reversed:
@pytest.fixture(scope="session", autouse=True)
async def _loop() -> AbstractEventLoop:
return new_event_loop()
@pytest.fixture()
def RE(_loop: AbstractEventLoop):
yield RunEngine(loop=_loop)There was a problem hiding this comment.
I'm going to check out locally and see if the tests pass
There was a problem hiding this comment.
From playing with it locally, it looks like
@pytest.fixture(scope="session", autouse=True)
async def _loop() -> AsyncGenerator[AbstractEventLoop]:
loop = new_event_loop()
yield loop
loop.stop()
@pytest.fixture(scope="session", autouse=True)
def RE(_loop: AbstractEventLoop):
yield RunEngine(loop=_loop, call_returns_result=True)Is the correct setup, and lets us remove the places where additional RunEngines are created in test_oav_utils.py
There was a problem hiding this comment.
Thanks, I agree it would be good to get the relationship between them so that the RE uses the same event loop. However, having the RE as @pytest.fixture(scope="session", autouse=True) seems wrong to me because now you have one RE for all tests and, unlike the event loop, the RE quite regularly holds state. For example, if one test adds a callback and forgets to remove it you're now using it in subsequent ones.
There was a problem hiding this comment.
Yeah, it's annoying that set_bluesky_loop is internal to bluesky, so just creating the loop and later creating the RunEngine with the same loop isn't sufficient.
There was a problem hiding this comment.
Discussed offline, we're going to merge this as is and follow up with #1501 if required
Fixes #1204
Repeated recreating of the RE was also causing issues with too many file handles open when running the tests locally. Not sure of the underlying cause for that but this seems like a reasonable thing to do anyway. It also seems to shave a couple of seconds off the tests too.
Additionally:
test_attach_data_session_metadata_wrapper_with_no_provider_is_noop, which didn't assert anything was broken in isolationInstructions to reviewer on how to test:
Checks for reviewer
dodal connect ${BEAMLINE}