For asyncio, you can write your test functions as coroutines if you use pytest-asyncio. You can even write test fixtures using coroutines. Mocking coroutine functions can be done using asynctest, although I've found that library a bit buggy.
Chris Jerdonek kirjoitti 02.07.2017 klo 00:00:
On Sat, Jul 1, 2017 at 1:42 PM, Nathaniel Smith <njs@pobox.com> wrote:
On Jul 1, 2017 3:11 AM, "Chris Jerdonek" <chris.jerdonek@gmail.com> wrote:Thanks, Nathaniel. The following would be overkill in my case, but
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()?
One possibility for handling this case with a minimum of mocking would be to
hook do_more so that it calls task.cancel and then calls the regular
do_more.
Beyond that it depends on what the actual functions are, I guess. If do_more
naturally blocks under some conditions then you might be able to set up
those conditions and then call cancel. Or you could try experimenting with
tests that call sleep(0) a fixed number of times before issuing the cancel,
and repeat with different iteration counts to find different cancel points.
your suggestion makes me wonder if it would make sense for there to be
testing tools that have functions to do things like "run the event
loop until <this future> is at <this line of code>." Do such things
exist? This is a little bit related to what Dima was saying about
tools.
--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/
_______________________________________________
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/