Skip to main content

This is a temporary pytest compatibility fork of pytest-asyncio-concurrent. The intent is to return to upstream once the fixes land there.

The fork registers concurrent tests as active during fixture setup and execution, as required by pytest 9.1. Async fixtures and concurrent tests share one session-owned event loop rather than relying on an implicit current loop.

PyPI version Python versions See Build Status on GitHub Actions

System/Integration tests can take a really long time.

And pytest-asyncio-concurrent A pytest plugin aiming to solve this by running asynchronous tests in true parallel, enabling faster execution for high I/O or network-bound test suites.

Unlike pytest-asyncio, which runs async tests sequentially, pytest-asyncio-concurrent takes advantage of Python’s asyncio capabilities to execute tests concurrently by specifying async group.

Note: This plugin would more or less Break Test Isolation Principle (for none function scoped fixture). Please make sure your tests is ok to run concurrently before you use this plugin.

Key Features

  • Giving the capability to run pytest async functions.

  • Providing granular control over Concurrency – See Async Group for details

    • Specifying Async Group to control tests that can run together.

    • Limitation: Only test functions defined under same direct parent can be put into same group.

  • asyncio_concurrent mark accept a timeout parameter, which would throw error when test reach the given time.

  • Compatible with pytest-asyncio.

Key Concept: Async Group

The plugin control tests concurrency by putting them into different groups.

  • Limitation: Each group can only contain tests under same direct parent. For example, class methods within same class, or functions within same file.

  • Explicitly specify group by providing group parameter to asyncio_concurrent mark.

    • All tests marked with same group name will be executed together.

    • All tests will be skipped if the Same Parent rule got violated.

  • Use default grouping strategy. The plugin accept --default-group-strategy cli parameter, or default_group_strategy in ini or toml file. Possible value: self, parent.

    • self(default): Each test will be executed by itself if no group provided.

    • parent: Tests will grouped by their parent node. For example, all method within same class will be grouped together.

Installation

Replace the upstream distribution with the fork; do not install both, since they provide the same Python package and pytest plugin:

$ pip uninstall pytest-asyncio-concurrent
$ pip install pytest-asyncio-concurrent-fork

The marker and plugin names are unchanged. With pytest 8.4 or later, projects can load only the plugins they use:

[tool.pytest.ini_options]
addopts = "--disable-plugin-autoload -p asyncio-concurrent"

Use plain @pytest.fixture for async fixtures owned by this plugin. If also using pytest-asyncio, explicitly load -p asyncio and use its strict mode so it does not take ownership of concurrent tests.

How this work?

This plugin extend pytest_runtestloop hook to handle async tests seperately.

In the ‘async loop’, tests are grouped by the group provided in the mark. and executed one group at a time.

In each group, instead of sequentially calling setup, call, teardown for individual test, these hooks are called for all tests in the group in batch.

The fixture lifecycle within group is handled by this plugin instead of pytest core, to work around pytest sequential test execution assumption.

Usage

Run test Sequentially

@pytest.mark.asyncio_concurrent
async def async_test_A():
    res = await wait_for_something_async()
    assert result.is_valid()

@pytest.mark.asyncio_concurrent
async def async_test_B():
    res = await wait_for_something_async()
    assert result.is_valid()

Run tests Concurrently

# the test below will run by itself
@pytest.mark.asyncio_concurrent
async def test_by_itself():
    res = await wait_for_something_async()
    assert result.is_valid()

# the two tests below will run concurrently
@pytest.mark.asyncio_concurrent(group="my_group")
async def test_groupA():
    res = await wait_for_something_async()
    assert result.is_valid()

# this one will have a 10s timeout
@pytest.mark.asyncio_concurrent(group="my_group", timeout=10)
async def test_groupB():
    res = await wait_for_something_async()
    assert result.is_valid()

Parametrized Tests

# the parametrized tests below will run sequential
@pytest.mark.asyncio_concurrent
@pytest.parametrize("p", [0, 1, 2])
async def test_parametrize_sequential(p):
    res = await wait_for_something_async()
    assert result.is_valid()

# the parametrized tests below will run concurrently
@pytest.mark.asyncio_concurrent(group="my_group")
@pytest.parametrize("p", [0, 1, 2])
async def test_parametrize_concurrent():
    res = await wait_for_something_async()
    assert result.is_valid()

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-asyncio-concurrent” is free and open source software

Release files for pytest-asyncio-concurrent-fork 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-asyncio-concurrent-fork 0.5.2
File Size Uploaded
pytest_asyncio_concurrent_fork-0.5.2.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-asyncio-concurrent-fork 0.5.2
File Interpreter ABI Platform
pytest_asyncio_concurrent_fork-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 34.3 kB

Release files / pytest_asyncio_concurrent_fork-0.5.2.tar.gz

Download URL pytest_asyncio_concurrent_fork-0.5.2.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5336c60cbd3975c56f59ab93564a6c5d6b2d4f1cfda9773b5a4732f08f15800d
BLAKE2b-256 checksum
How to use checksums
e0b5ea8236af31262a771fcf55d0071c922f9da351a573e2bcae54b42fcb2c10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pytest_asyncio_concurrent_fork-0.5.2-py3-none-any.whl

Download URL pytest_asyncio_concurrent_fork-0.5.2-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
310f141e6cc8450679ce2a43e5ed6b55da51fd06502b7fb9f66e264db996103c
BLAKE2b-256 checksum
How to use checksums
bd0762a5ed65988b8af755308661f4d7cc26b7443fd73d62ab3b1afc4dec38fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page