You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently came across this error in my unit tests:
RuntimeError: This event loop is already running
The error doesn't come from streamz, it's from jupyter_core, in this recent change.
But it is triggered because my streamz tests don't clean up properly after them selves.
They leave the global async event loop, asyncio.get_event_loop(), in a running state.
To fix it I had to add this fixture to my unit tests:
If it were a scope="session" fixture, I see no reason it shouldn't be added to conftest. Some of these issues may still be coming from the mixture of tornado and asyncio styles.
@martindurant sorry I wasn't clear. I'm not suggesting we add this fixture to conftest.
I'm suggesting we put it in unit_test.py the same way there is the clean fixture. So users of streamz can use that new fixture in their unit tests. I for example use the clean fixture in some of my tests already.
Certainly that would be fine too. Also, a little documentation around this, as linked by @amotl would make sense, for anyone else that might be doing this kind of thing.
Activity
martindurant commentedon Oct 13, 2023
If it were a
scope="session"fixture, I see no reason it shouldn't be added to conftest. Some of these issues may still be coming from the mixture of tornado and asyncio styles.0x26res commentedon Oct 15, 2023
@martindurant sorry I wasn't clear. I'm not suggesting we add this fixture to conftest.
I'm suggesting we put it in unit_test.py the same way there is the clean fixture. So users of streamz can use that new fixture in their unit tests. I for example use the
cleanfixture in some of my tests already.amotl commentedon Oct 15, 2023
Hi there,
we are not 100% sure, but we think we have been tripped by the same issue when conceiving LorryStream.
We have been able to work around it by leveraging the pytest-asyncio-cooperative package. A corresponding example test case is demonstrated at 1.
With kind regards,
Andreas.
Footnotes
https://github.com/daq-tools/lorrystream/blob/b0412d7/tests/test_engine.py#L40-L58 ↩
martindurant commentedon Oct 16, 2023
Certainly that would be fine too. Also, a little documentation around this, as linked by @amotl would make sense, for anyone else that might be doing this kind of thing.