On Sat, Jul 1, 2017 at 1:42 PM, Nathaniel Smith <n...@pobox.com> wrote: > On Jul 1, 2017 3:11 AM, "Chris Jerdonek" <chris.jerdo...@gmail.com> wrote: > 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.
Thanks, Nathaniel. The following would be overkill in my case, but 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/