README.rst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. pytest-asyncio
  2. ==============
  3. .. image:: https://img.shields.io/pypi/v/pytest-asyncio.svg
  4. :target: https://pypi.python.org/pypi/pytest-asyncio
  5. .. image:: https://github.com/pytest-dev/pytest-asyncio/workflows/CI/badge.svg
  6. :target: https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI
  7. .. image:: https://codecov.io/gh/pytest-dev/pytest-asyncio/branch/main/graph/badge.svg
  8. :target: https://codecov.io/gh/pytest-dev/pytest-asyncio
  9. .. image:: https://img.shields.io/pypi/pyversions/pytest-asyncio.svg
  10. :target: https://github.com/pytest-dev/pytest-asyncio
  11. :alt: Supported Python versions
  12. .. image:: https://img.shields.io/badge/code%20style-black-000000.svg
  13. :target: https://github.com/ambv/black
  14. `pytest-asyncio <https://pytest-asyncio.readthedocs.io/en/latest/>`_ is a `pytest <https://docs.pytest.org/en/latest/contents.html>`_ plugin. It facilitates testing of code that uses the `asyncio <https://docs.python.org/3/library/asyncio.html>`_ library.
  15. 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:
  16. .. code-block:: python
  17. @pytest.mark.asyncio
  18. async def test_some_asyncio_code():
  19. res = await library.do_something()
  20. assert b"expected result" == res
  21. More details can be found in the `documentation <https://pytest-asyncio.readthedocs.io/en/latest/>`_.
  22. Note that test classes subclassing the standard `unittest <https://docs.python.org/3/library/unittest.html>`__ library are not supported. Users
  23. are advised to use `unittest.IsolatedAsyncioTestCase <https://docs.python.org/3/library/unittest.html#unittest.IsolatedAsyncioTestCase>`__
  24. or an async framework such as `asynctest <https://asynctest.readthedocs.io/en/latest>`__.
  25. pytest-asyncio is available under the `Apache License 2.0 <https://github.com/pytest-dev/pytest-asyncio/blob/main/LICENSE>`_.
  26. Installation
  27. ------------
  28. To install pytest-asyncio, simply:
  29. .. code-block:: bash
  30. $ pip install pytest-asyncio
  31. This is enough for pytest to pick up pytest-asyncio.
  32. Contributing
  33. ------------
  34. Contributions are very welcome. Tests can be run with ``tox``, please ensure
  35. the coverage at least stays the same before you submit a pull request.