Open axc450 opened 4 years ago
Additionally, the below works:
with self.assertRaises(ValueError):
await x(1, 2)
But this only works when in isolation in its own test. You cant do something like this:
# Lets just say x() is designed to add 2 numbers
result = await x(1, 2)
self.assertEqual(x, 3)
with self.assertRaises(ValueError):
await x(None, 2)
Hello,
self.assertAsyncRaises
accepts an awaitable as argument so you should write:
await self.assertAsyncRaises(ValueError, x(1, 2))
It's actually a very simple shorthand: https://asynctest.readthedocs.io/en/latest/_modules/asynctest/case.html#TestCase.assertAsyncRaises
assertAsyncRaises don't accept the coroutine function + args for several reasons:
It's true that the doc is very light though, I'll update it.
Thanks! I also had an issue with my tests not properly resetting my environment, so I think that may have caused some of the confusion. Ignore anything here that makes no sense 🙂
I think just an example added to the docs would be great!
Hi,
Im having a bit of trouble using
assertAsyncRaises
. I have read the docs and tried various things:Here is how I would usually write a test for the dummy function
x
. Usingasynctest
:I would except just the first/last example should work; I would assume it would look something like this under the hood: