- Notifications
You must be signed in to change notification settings - Fork 167
Description
Hello pytest-asyncio developers! We've been using your plugin for a while. So much so that we now have tens of thousands of tests and hundreds of thousands of fixture arguments and ... it takes over three minutes to collect our tests.
Of that time, roughly two and a half minutes is taken up by pytest-asyncio. Specifically, this piece of code:
pytest-asyncio/pytest_asyncio/plugin.py
Line 213 in edb9ae0
| if fixturedef in processed_fixturedefs or not _is_coroutine_or_asyncgen( |
That ends up calling https://github.com/python/cpython/blob/3aea6c4823e90172c9bc36cd20dc51b295d8a3c4/Lib/inspect.py#L384, which unwraps each fixture argument, makes sure it's a function, and then finally checks its co_flags to see if it's been marked as a coroutine function. The thing is, because you're feeding fixtures through, they tend to all be functions.
We ended up forking the plugin and inlining iscoroutinefunction and isasyncgenfunction - just the bit masking lines. Then we removed the code that was attaching the scoped_event_loop fixture because we don't use it and it was compounding the issue described above. That took us down to one minute.
I think it would help a lot to make the same changes here upstream. You could also swap the ordering of the comparison with
pytest-asyncio/pytest_asyncio/plugin.py
Line 217 in edb9ae0
| if not _is_asyncio_fixture_function(func) and asyncio_mode == Mode.STRICT: |
scoped_event_loop optional would bring your plugin even closer to baseline performance.