test_async.py 558 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. asyncio = pytest.importorskip("asyncio")
  4. m = pytest.importorskip("pybind11_tests.async_module")
  5. @pytest.fixture
  6. def event_loop():
  7. loop = asyncio.new_event_loop()
  8. yield loop
  9. loop.close()
  10. async def get_await_result(x):
  11. return await x
  12. def test_await(event_loop):
  13. assert 5 == event_loop.run_until_complete(get_await_result(m.SupportsAsync()))
  14. def test_await_missing(event_loop):
  15. with pytest.raises(TypeError):
  16. event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync()))