I have a question about testing async code.

Say I have a coroutine:

    async def do_things():
        await do_something()
        await do_more()
        await do_even_more()

And future:

    task = ensure_future(do_things())

Is there a way to write a test case to check that task.cancel() would
behave correctly if, say, do_things() is waiting at the line
do_more()?

In real life, this situation can happen if a function like the
following is called, and an exception happens in one of the given
tasks.  One of the tasks in the "pending" list could be at the line
do_more().

    done, pending = await asyncio.wait(tasks,
                         return_when=asyncio.FIRST_EXCEPTION)

But in a testing situation, you don't necessarily have control over
where each task ends up when FIRST_EXCEPTION occurs.

Thanks,
--Chris
_______________________________________________
Async-sig mailing list
Async-sig@python.org
https://mail.python.org/mailman/listinfo/async-sig
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to