August 2018
Beginner
160 pages
4h 8m
English
The asyncio (https://docs.python.org/3/library/asyncio.html) module is one of the hot new additions to Python 3, providing a new framework for asynchronous applications. The pytest-asyncio plugin lets you write asynchronous test functions, making it a snap to test your asynchronous code.
All you need to do is make your test function async def and mark it with the asyncio mark:
@pytest.mark.asyncioasync def test_fetch_requests(): requests = await fetch_requests("example.com/api") assert len(requests) == 2
The plugin also manages the event loop behind the scenes, providing a few options on how to change it if you need to use a custom event loop.
Read now
Unlock full access