An async TestCase with support for structured concurrency context managers

Currently the IsolatedAsyncioTestCase is an async version of unittest.TestCase but:

  • it’s coupled to asyncio and I’d like a stdlib TestCase class that works for twisted and trio
  • It doesn’t support structured concurrency context managers (yield-safe)
  • It starts and stops the asyncio event loop rather than just using asyncio.run which means sometimes async generator finalization doesn’t work correctly

If a new one were designed to work like AsyncExitStack both of my problems with it could be fixed at the same time

I recommend that you try to build something robust that satisfies your needs as a 3rd party package first. Once that is robust and has gained (some) traction we can see if we can add it to the stdlib (it would have to be designed to fit well in the stdlib).

1 Like