Skip to main content

Pytest plugin for testing async python code

Project description

pytest-aio

pytest-aio – Is a simple pytest plugin for testing async python code

The plugin supports all popular python async libraries: (Asyncio, Trio, Curio)

pytest-aio has been strongly influenced by AnyIO. Since 2021-02-09 AnyIO has dropped support for Curio, so the plugin has been created.

Tests Status PYPI Version Python Versions

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 run all your async test functions/fixtures.

async def test_async():
    assert True

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

# 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):

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

To set a specific backends for a single test only:

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

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

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

License

Licensed under a MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-aio-0.5.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

pytest_aio-0.5.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-aio-0.5.2.tar.gz.

File metadata

  • Download URL: pytest-aio-0.5.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for pytest-aio-0.5.2.tar.gz
Algorithm Hash digest
SHA256 b5f7c0ad020f13c16c9d8b9712ee9e95dbff71e9c5297c9639eb9127b9d05de4
MD5 7133183a866bf06d4ecea2e714e3dd27
BLAKE2b-256 ea25910e813ced0e528077f6a8520ca9fbf5b0669e3e8688df62582eddafd12a

See more details on using hashes here.

File details

Details for the file pytest_aio-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: pytest_aio-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for pytest_aio-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 671ec5268a200aab6cd1e3fd734801e2b7007ad9cd879d8f0a58096201eeeb85
MD5 d6524d5c8d34f8f4bcf5e8d2ecf37500
BLAKE2b-256 0dea029fbe236ef43d75161fec97aaf12f0e6951b68358f07f6e2bc0b9fb6900

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page