PyHamcrest icon indicating copy to clipboard operation
PyHamcrest copied to clipboard

Add matcher for exceptions in asyncio future

Open keis opened this issue 3 years ago • 4 comments

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

keis avatar Mar 11 '21 16:03 keis

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.

brunns avatar Mar 12 '21 10:03 brunns

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 :)

keis avatar Mar 12 '21 12:03 keis

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.

brunns avatar Mar 12 '21 12:03 brunns

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 :)

keis avatar Mar 12 '21 15:03 keis