Description
The recent changes deprecated redefining the event_loop fixture, but provided no replacement for scope=package
. Presumably the move away from the fixture was taken for good reasons, but I'd like to suggest support for (at least) package scope is worth having.
Package scope is really handy: you can have a directory structure like this:
a/
├─ test_foo.py
├─ test_bar.py
b/
├─ test_baz.py
├─ test_blah.py
with expensive fixtures per-directory, spin them up once per dir and then clean them up (freeing ram) before moving to the next dir.
I know this will work just fine with a session scoped event loop (which is also no longer possible?), but matching the event loop scope to the context has advantages:
- every new testing context (new package) starts in a clean loop
- failing fixtures or leftover state (locks, unawaited coros) throw at the package level, so you get debugging quickly
- certain exotic failure modes where stale state on the loop is inadvertently cleaned up elsewhere (ahem) only show if the loop is explicitly torn down on exiting the context, effectively asserting nothing is running on it
Thus I'd like to suggest support for package scope is added to asyncio_event_loop
. For completeness, the scopes are:
- function: default
- class: already available
- module: already available
- package: missing
- session: missing
I also think it is worth implementing session scoping, although I think package
is normally the right scope. It's possible I'm missing something here and this is already possible.