Jeremy Maitin-Shepard | a3f4a0e | 2019-07-18 00:02:35 -0700 | [diff] [blame] | 1 | import asyncio |
| 2 | import pytest |
| 3 | from pybind11_tests import async_module as m |
| 4 | |
| 5 | |
| 6 | @pytest.fixture |
| 7 | def event_loop(): |
| 8 | loop = asyncio.new_event_loop() |
| 9 | yield loop |
| 10 | loop.close() |
| 11 | |
| 12 | |
| 13 | async def get_await_result(x): |
| 14 | return await x |
| 15 | |
| 16 | |
| 17 | def test_await(event_loop): |
| 18 | assert 5 == event_loop.run_until_complete(get_await_result(m.SupportsAsync())) |
| 19 | |
| 20 | |
| 21 | def test_await_missing(event_loop): |
| 22 | with pytest.raises(TypeError): |
| 23 | event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync())) |