{"id":24417,"library":"pytest-asyncio-cooperative","title":"pytest-asyncio-cooperative","description":"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.","status":"active","version":"0.40.0","language":"python","source_language":"en","source_url":"https://github.com/a-detiste/pytest-asyncio-cooperative","tags":["pytest","asyncio","testing","plugin","cooperative"],"install":[{"cmd":"pip install pytest-asyncio-cooperative","lang":"bash","label":"pip"}],"dependencies":[{"reason":"Required plugin","package":"pytest","optional":false},{"reason":"Underlying async test support","package":"pytest-asyncio","optional":false}],"imports":[{"note":"","wrong":"","symbol":"pytest.mark.asyncio_cooperative","correct":"from pytest_asyncio_cooperative import pytest_configure"},{"note":"Not needed; plugin auto-registers.","wrong":"import pytest_asyncio_cooperative","symbol":"pytest_configure","correct":"from pytest_asyncio_cooperative import pytest_configure"}],"quickstart":{"code":"# conftest.py\nimport asyncio\nimport sys\n\n@pytest.fixture(scope=\"session\")\ndef event_loop():\n    loop = asyncio.new_event_loop()\n    asyncio.set_event_loop(loop)\n    yield loop\n    loop.close()\n\n# test_async.py\nimport pytest\n\n@pytest.mark.asyncio_cooperative\nasync def test_async_example():\n    await asyncio.sleep(0.1)\n    assert True","lang":"python","description":"Basic setup: define a session-scoped event_loop fixture (if not using async fixtures) and mark tests with @pytest.mark.asyncio_cooperative."},"warnings":[{"fix":"Use @pytest.mark.asyncio_cooperative instead of @pytest.mark.asyncio.","message":"The 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Define a session-scoped event_loop fixture in conftest.py that creates a new event loop.","message":"The 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'.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure all async tests within the session use the same event loop; do not create new loops manually.","message":"Tests 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add a session-scoped event_loop fixture in conftest.py:\n\n@pytest.fixture(scope=\"session\")\ndef event_loop():\n    loop = asyncio.new_event_loop()\n    asyncio.set_event_loop(loop)\n    yield loop\n    loop.close()","cause":"Missing session-scoped event_loop fixture.","error":"RuntimeError: There is no current event loop in thread 'MainThread'"},{"fix":"Move the event_loop fixture to the root conftest.py (or ensure the conftest.py is in the top-level test directory).","cause":"The event_loop fixture is defined in a conftest.py inside a subpackage, but pytest-asyncio-cooperative expects it at the root conftest or the test directory.","error":"Fixture 'event_loop' cannot be a session-scoped fixture because it is defined in a non-top-level conftest"},{"fix":"Ensure pytest-asyncio-cooperative is installed and the conftest.py is found. The marker is automatically registered when the plugin is active.","cause":"Attempting to import pytest.mark without the marker being registered.","error":"AttributeError: module 'pytest' has no attribute 'mark'"},{"fix":"Upgrade pytest-asyncio and pytest-asyncio-cooperative to latest versions. If the warning persists, use scope='session' event_loop fixture as recommended.","cause":"Using an older version of pytest-asyncio that suppresses the warning, but pytest-asyncio-cooperative may use the old fixture pattern.","error":"DeprecationWarning: The 'event_loop' fixture is deprecated"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}