Registry / testing / pytest-asyncio-cooperative

pytest-asyncio-cooperative

JSON →
library0.40.0pypypi✓ verified 82d ago

A pytest plugin that runs all async tests cooperatively using a single event loop, avoiding event loop conflicts and improving performance. Current version: 0.40.0, requires Python >=3.8. Released under MIT license; maintenance cadence is irregular.

pip install pytest-asyncio-cooperative
INSTALL
IMPORT
SIG · PYTEST-ASYNCIO-COO
P
pytest-asyncio-cooperative
testingpythonv0.40.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.40.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Lock
from pytest_asyncio_cooperative import Lock
from pytest_asyncio_cooperative import pytest_configure
asyncio
from pytest_asyncio_cooperative import asyncio
from pytest_asyncio_cooperative import pytest_configure

Basic setup: define a session-scoped event_loop fixture (if not using async fixtures) and mark tests with @pytest.mark.asyncio_cooperative.

# conftest.py import asyncio import sys @pytest.fixture(scope="session") def event_loop(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) yield loop loop.close() # test_async.py import pytest @pytest.mark.asyncio_cooperative async def test_async_example(): await asyncio.sleep(0.1) assert True
Debug
Known issues
gotchaThe marker is @pytest.mark.asyncio_cooperative, not @pytest.mark.asyncio. Using the wrong marker will run tests in isolated loops and may cause event loop conflicts.
fix
Use @pytest.mark.asyncio_cooperative instead of @pytest.mark.asyncio.
affects: all
gotchaThe plugin requires a session-scoped event_loop fixture. If you forget to define it, you may get 'RuntimeError: There is no current event loop in thread'.
fix
Define a session-scoped event_loop fixture in conftest.py that creates a new event loop.
affects: all
gotchaTests that call loop.run_until_complete() or create sub-loops may interfere with the shared loop. Avoid mixing cooperative tests with those that manage their own loops.
fix
Ensure all async tests within the session use the same event loop; do not create new loops manually.
affects: all
Upgrade
Version history
0.40.0latest on PyPI · released Jun 24, 2025
Audit
Dependencies
pytestrequiredRequired plugin
pytest-asynciorequiredUnderlying async test support
Agent activity
7 hits · last 30 days
node
6
Resources
pytest-asyncio-cooperative — pip install pytest-asyncio-cooperative · libregistry