Replies: 1 comment
-
Disclaimer: I'm one of the maintainers and I cannot answer for the author of pytest-asyncio. Maybe @Tinche can chime in on this. The default behavior of pytest-asyncio is to run each test case in a separate asyncio event loop. This should guarantee isolation between tests. However, there are valid use cases, where the event loop should persist across multiple test cases, for example when the user starts a web server and runs API requests against that server to verify its behavior. The officially supported way to achieve this is to redefine the pytest-asyncio v0.21.0 has the additional limitation that event_loop fixture scopes must not overlap or they will trigger a DeprecationWarning (see #531 ). As such, it is preferred to set a scope that is narrower than session, especially if you want to run unit tests (with per-test event loop isolation) and larger-than-unit tests (with larger event loop scope) in the same session. |
Beta Was this translation helpful? Give feedback.
-
Originally posted here: #531 (comment) by @serpulga
I encountered the issue function scoped fixture event_loop with a session scoped request object, which forces me to create an event loop fixture that is session scoped.
My question is, how does the author(s) feel about this approach? It seems the intended use-case was for the event loop to be function-scoped. Is it common enough to call for "official" support for session-scoped even loops?
Beta Was this translation helpful? Give feedback.
All reactions