Hello
I just tryed to use self.assertNumQueries in full async test.
Code ref: django/django/test/testcases.py at 1feedc8ef8a34484cb5afe33f5c45b543b860210 · django/django · GitHub
I also tryed to hack the issue like:
async with self.assertNumQueries(1):
await self.async_method(some_kwargs=some_kwargs)
or
await sync_to_async(self.assertNumQueries)(1, func=async_method, some_kwargs=some_kwargs)
...
def assertNumQueries(self, num, func=None, *args, using=DEFAULT_DB_ALIAS, **kwargs):
conn = connections[using]
context = _AssertNumQueriesContext(self, num, conn)
if func is None:
return context
with context:
async_to_sync(func)(*args, **kwargs)
But obviously the event loop is not find event if a new one is created.
It doesn’t look too hard to add aenter and aexit methods to _AssertNumQueriesContext that then call the original method but in a sync context. I may be ablea to do it by myself. Just wanted to check if there is maybe another obvious solution I missed