pytest-aio


Namepytest-aio JSON
Version 1.5.0 PyPI version JSON
download
home_pagehttps://github.com/klen/pytest-aio
SummaryPytest plugin for testing async python code
upload_time2023-02-03 06:45:22
maintainer
docs_urlNone
authorKirill Klenov
requires_python>=3.7
licenseMIT
keywords pytest asyncio trio curio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pytest-aio
==========

.. _description:

**pytest-aio** -- Is a simple pytest_ plugin for testing any async python code

.. _badges:

.. image:: https://github.com/klen/pytest-aio/workflows/tests/badge.svg
    :target: https://github.com/klen/pytest-aio/actions
    :alt: Tests Status

.. image:: https://img.shields.io/pypi/v/pytest-aio
    :target: https://pypi.org/project/pytest-aio/
    :alt: PYPI Version

.. image:: https://img.shields.io/pypi/pyversions/pytest-aio
    :target: https://pypi.org/project/pytest-aio/
    :alt: Python Versions

Features
--------

- Supports all most popular async python libraries: `Asyncio`_, `Trio`_ and Curio_
- Automatically run your async tests
- Works with `contextvars` correctly (supports it for async/sync fixtures)
- Supports `trio-asyncio`_

.. _contents:

.. contents::

.. _requirements:

Requirements
=============

- python >= 3.7

Installation
=============

**pytest-aio** should be installed using pip: ::

    pip install pytest-aio

optionally extras are available: ::

    pip install pytest-aio[curio,trio]

Usage
=====

When installed the plugin runs all your async test functions/fixtures.

.. code-block:: python

    async def test_async():
        assert True

No need to mark your async tests. Just run pytest as is.

Async fixtures for sync tests
-----------------------------

If you plan use async fixtures for sync tests, please ensure you have to
include `aiolib` fixture:

.. code-block:: python

    # It's important to add aiolib fixture here
    def test_with_async_fixtures(async_fixture, aiolib):
        assert async_fixture == 'value from async fixture'

As an alternative, If you are doing the async fixtures yourself, you can add
`aiolib` inside them:

.. code-block:: python

    @pytest.fixture
    async def async_fixture(aiolib):
        return 'value from async fixture'

    # So for the test we don't need to implicity use `aiolib` anymore
    def test_with_async_fixtures(async_fixture):
        assert async_fixture == 'value from async fixture'


Customize async libraries
-------------------------

By default each test function will be run with asyncio, trio, curio backends
consistently (only if trio/curio are installed). But you can customise the
libraries for all your tests creating the global fixture:

.. code-block:: python

    # Run all tests with Asyncio/Trio only
    @pytest.fixture(params=['asyncio', 'trio'])
    def aiolib(request):
        assert request.param

If you want to specify different options for the selected backend, you can do
so by passing a tuple of (backend name, options dict):

.. code-block:: python

    @pytest.fixture(params=[
        pytest.param(('asyncio', {'use_uvloop': False}), id='asyncio'),
        pytest.param(('asyncio', {'use_uvloop': True}), id='asyncio+uvloop'),
        pytest.param(('trio', {'trio_asyncio': True}), id='trio+asyncio'),
        pytest.param(('curio', {'debug': True}), id='curio'),
    ])
    def aiolib(request):
        assert request.param

To set a specific backends for a single test only:

.. code-block:: python

    @pytest.mark.parametrize('aiolib', ['asyncio'])
    async def only_with_asyncio():
        await asyncio.sleep(1)
        assert True

Helpers
-------

The plugin contains `aiosleep` fixture. It's an equivalent to `asyncio.sleep`,
`trio.sleep`, `curio.sleep` for current running library.


.. _bugtracker:

Bug tracker
===========

If you have any suggestions, bug reports or
annoyances please report them to the issue tracker
at https://github.com/klen/asgi-tools/issues

.. _contributing:

Contributing
============

Development of the project happens at: https://github.com/klen/pytest-aio

.. _license:

License
========

Licensed under a `MIT license`_.


.. _links:

.. _Asyncio: https://docs.python.org/3/library/asyncio.html
.. _Curio: https://curio.readthedocs.io/en/latest/
.. _MIT license: http://opensource.org/licenses/MIT
.. _Trio: https://trio.readthedocs.io/en/stable/index.html
.. _klen: https://github.com/klen
.. _pytest: https://docs.pytest.org/en/stable/
.. _AnyIO: https://github.com/agronholm/anyio
.. _trio-asyncio: https://github.com/python-trio/trio-asyncio 



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klen/pytest-aio",
    "name": "pytest-aio",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "pytest,asyncio,trio,curio",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8e/45/837a78dd418a0b4f795c1fdd850b40d300c05e728480508a3ae53d5cde64/pytest-aio-1.5.0.tar.gz",
    "platform": null,
    "description": "pytest-aio\n==========\n\n.. _description:\n\n**pytest-aio** -- Is a simple pytest_ plugin for testing any async python code\n\n.. _badges:\n\n.. image:: https://github.com/klen/pytest-aio/workflows/tests/badge.svg\n    :target: https://github.com/klen/pytest-aio/actions\n    :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/pytest-aio\n    :target: https://pypi.org/project/pytest-aio/\n    :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-aio\n    :target: https://pypi.org/project/pytest-aio/\n    :alt: Python Versions\n\nFeatures\n--------\n\n- Supports all most popular async python libraries: `Asyncio`_, `Trio`_ and Curio_\n- Automatically run your async tests\n- Works with `contextvars` correctly (supports it for async/sync fixtures)\n- Supports `trio-asyncio`_\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.7\n\nInstallation\n=============\n\n**pytest-aio** should be installed using pip: ::\n\n    pip install pytest-aio\n\noptionally extras are available: ::\n\n    pip install pytest-aio[curio,trio]\n\nUsage\n=====\n\nWhen installed the plugin runs all your async test functions/fixtures.\n\n.. code-block:: python\n\n    async def test_async():\n        assert True\n\nNo need to mark your async tests. Just run pytest as is.\n\nAsync fixtures for sync tests\n-----------------------------\n\nIf you plan use async fixtures for sync tests, please ensure you have to\ninclude `aiolib` fixture:\n\n.. code-block:: python\n\n    # It's important to add aiolib fixture here\n    def test_with_async_fixtures(async_fixture, aiolib):\n        assert async_fixture == 'value from async fixture'\n\nAs an alternative, If you are doing the async fixtures yourself, you can add\n`aiolib` inside them:\n\n.. code-block:: python\n\n    @pytest.fixture\n    async def async_fixture(aiolib):\n        return 'value from async fixture'\n\n    # So for the test we don't need to implicity use `aiolib` anymore\n    def test_with_async_fixtures(async_fixture):\n        assert async_fixture == 'value from async fixture'\n\n\nCustomize async libraries\n-------------------------\n\nBy default each test function will be run with asyncio, trio, curio backends\nconsistently (only if trio/curio are installed). But you can customise the\nlibraries for all your tests creating the global fixture:\n\n.. code-block:: python\n\n    # Run all tests with Asyncio/Trio only\n    @pytest.fixture(params=['asyncio', 'trio'])\n    def aiolib(request):\n        assert request.param\n\nIf you want to specify different options for the selected backend, you can do\nso by passing a tuple of (backend name, options dict):\n\n.. code-block:: python\n\n    @pytest.fixture(params=[\n        pytest.param(('asyncio', {'use_uvloop': False}), id='asyncio'),\n        pytest.param(('asyncio', {'use_uvloop': True}), id='asyncio+uvloop'),\n        pytest.param(('trio', {'trio_asyncio': True}), id='trio+asyncio'),\n        pytest.param(('curio', {'debug': True}), id='curio'),\n    ])\n    def aiolib(request):\n        assert request.param\n\nTo set a specific backends for a single test only:\n\n.. code-block:: python\n\n    @pytest.mark.parametrize('aiolib', ['asyncio'])\n    async def only_with_asyncio():\n        await asyncio.sleep(1)\n        assert True\n\nHelpers\n-------\n\nThe plugin contains `aiosleep` fixture. It's an equivalent to `asyncio.sleep`,\n`trio.sleep`, `curio.sleep` for current running library.\n\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/asgi-tools/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of the project happens at: https://github.com/klen/pytest-aio\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n\n.. _links:\n\n.. _Asyncio: https://docs.python.org/3/library/asyncio.html\n.. _Curio: https://curio.readthedocs.io/en/latest/\n.. _MIT license: http://opensource.org/licenses/MIT\n.. _Trio: https://trio.readthedocs.io/en/stable/index.html\n.. _klen: https://github.com/klen\n.. _pytest: https://docs.pytest.org/en/stable/\n.. _AnyIO: https://github.com/agronholm/anyio\n.. _trio-asyncio: https://github.com/python-trio/trio-asyncio \n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pytest plugin for testing async python code",
    "version": "1.5.0",
    "split_keywords": [
        "pytest",
        "asyncio",
        "trio",
        "curio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f295da3313b225609f83885e02098172ee63b897dcc3a278c0587da0e7c80907",
                "md5": "a585342b2657fa5b591290ac2677a851",
                "sha256": "427125f60445ded1b4eb16dcc30c9dd20b1c9181ccacfc5c678e49ae773ec127"
            },
            "downloads": -1,
            "filename": "pytest_aio-1.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a585342b2657fa5b591290ac2677a851",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6918,
            "upload_time": "2023-02-03T06:45:20",
            "upload_time_iso_8601": "2023-02-03T06:45:20.452334Z",
            "url": "https://files.pythonhosted.org/packages/f2/95/da3313b225609f83885e02098172ee63b897dcc3a278c0587da0e7c80907/pytest_aio-1.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e45837a78dd418a0b4f795c1fdd850b40d300c05e728480508a3ae53d5cde64",
                "md5": "b3cb7101583f4d82c2994a760568fadb",
                "sha256": "a00d0378adac57d6c24841b8d898aa083a4cb2ae5f94a339f5f0c8b1b5d16677"
            },
            "downloads": -1,
            "filename": "pytest-aio-1.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b3cb7101583f4d82c2994a760568fadb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6847,
            "upload_time": "2023-02-03T06:45:22",
            "upload_time_iso_8601": "2023-02-03T06:45:22.468572Z",
            "url": "https://files.pythonhosted.org/packages/8e/45/837a78dd418a0b4f795c1fdd850b40d300c05e728480508a3ae53d5cde64/pytest-aio-1.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-03 06:45:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "klen",
    "github_project": "pytest-aio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-aio"
}
        
Elapsed time: 0.07238s