PyHamcrest
PyHamcrest copied to clipboard
Add matcher for exceptions in asyncio future
WIP: Based on raises matcher but adapted to deal with future objects.
Example of use
assert_that(
await resolved(raise_exception()),
future_exception(AssertionError))
)
The resolved helper is used to create resolved future objects in async code. It takes a "future like" object and waits for it to complete.
Ref #155
Ah - doing this in a way which is compatible with Python versions prior to 3.9 is going to be... interesting. FYI, PyHamcrest works with versions 3.6 and up as of now - all currently supported versions.
I don't think the await syntax should be a problem it was introduced in 3.4 (Or there about) IIRC, and before that there was the 'yield from' stuff that should work even if not as pretty to look at :)
Oh, cool - but something's not working with older versions. FWIW, I usually do tox -e py36,py39,lint
before committing - I find that's enough to give me a good idea it'll work.
Nice change, BTW - I do love to see tests and docs in a PR.
@offbyone has added towncrier to the build, so at some point we;'ll need an entry in changelog.d
too.
So turns out there was two issues Future[T]
does not work in python3.6 and IsolatedAsyncioTestCase
was only added in 3.8
I'll update with some more tests etc later :)