For testing purposes, I would like to measure the time that is spent on blocking execution of a coroutine (i.e, excluding the time for which it is suspended).
For example:
import trio
import time
async def under_test():
await trio.sleep(2)
time.sleep(3)
async def measure():
with measure_blocking_time() as ctx: # or something like that
await under_test()
assert ctx.elapsed == 3
trio.run(measure)
How do I do that?
(There seems to be a somewhat hacky way to do this when using asyncio - hopefully it can be done more nicer in Trio?)