pytest-asyncio is a pytest plugin. It facilitates testing of code that uses the asyncio library.
Specifically, pytest-asyncio provides support for coroutines as test functions. This allows users to await code inside their tests. For example, the following code is executed as a test item by pytest:
@pytest.mark.asyncio
async def test_some_asyncio_code():
res = await library.do_something()
assert b"expected result" == resMore details can be found in the documentation.
Note that test classes subclassing the standard unittest library are not supported. Users are advised to use unittest.IsolatedAsyncioTestCase or an async framework such as asynctest.
pytest-asyncio is available under the Apache License 2.0.
To install pytest-asyncio, simply:
$ pip install pytest-asyncioThis is enough for pytest to pick up pytest-asyncio.
Contributions are very welcome.
Tests can be run with tox. Please ensure that all tests are passing and
coverage at least stays the same before opening a pull request and marking it as
ready for review.
Use of AI in contributions, including issues, pull requests, and comments, must follow our AI policy.