Description
pytest-asyncio ============== .. image:: https://img.shields.io/pypi/v/pytest-asyncio.svg :target: https://pypi.python.org/pypi/pytest-asyncio .. image:: https://github.com/pytest-dev/pytest-asyncio/workflows/CI/badge.svg :target: https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI .. image:: https://codecov.io/gh/pytest-dev/pytest-asyncio/branch/main/graph/badge.svg :target: https://codecov.io/gh/pytest-dev/pytest-asyncio .. image:: https://img.shields.io/pypi/pyversions/pytest-asyncio.svg :target: https://github.com/pytest-dev/pytest-asyncio :alt: Supported Python versions .. image:: https://img.shields.io/badge/Matrix-%23pytest--asyncio-brightgreen :alt: Matrix chat room: #pytest-asyncio :target: https://matrix.to/#/#pytest-asyncio:matrix.org `pytest-asyncio <https://pytest-asyncio.readthedocs.io/en/latest/>`_ is a `pytest <https://docs.pytest.org/en/latest/contents.html>`_ plugin. It facilitates testing of code that uses the `asyncio <https://docs.python.org/3/library/asyncio.html>`_ library. Specifically, pytest-asyncio provides support for coroutines as test functions. This allows users to *await* code inside their tests. For example, the following code is executed as a test item by pytest: .. code-block:: python @pytest.mark.asyncio async def test_some_asyncio_code(): res = await library.do_something() assert b"expected result" == res More details can be found in the `documentation <https://pytest-asyncio.readthedocs.io/en/latest/>`_. Note that test classes subclassing the standard `unittest <https://docs.python.org/3/library/unittest.html>`__ library are not supported. Users are advised to use `unittest.IsolatedAsyncioTestCase <https://docs.python.org/3/library/unittest.html#unittest.IsolatedAsyncioTestCase>`__ or an async framework such as `asynctest <https://asynctest.readthedocs.io/en/latest>`__. pytest-asyncio is available under the `Apache License 2.0 <https://github.com/pytest-dev/pytest-asyncio/blob/main/LICENSE>`_. Installation ------------ To install pytest-asyncio, simply: .. code-block:: bash $ pip install pytest-asyncio This is enough for pytest to pick up pytest-asyncio. 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.
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 1.3.0 | Imported from PyPI (1.3.0) | Low | 4/21/2026 |
| v1.4.0a1 | # [1.4.0a1](https://github.com/pytest-dev/pytest-asyncio/tree/1.4.0a1) - 2026-04-15 ## Added - Added the `pytest_asyncio_loop_factories` hook to parametrize asyncio tests with custom event loop factories. The hook returns a mapping of factory names to loop factories, and `pytest.mark.asyncio(loop_factories=[...])` selects a subset of configured factories per test. When a single factory is configured, test names are unchanged on pytest 8.4+. Synchronous `@pytest_asyncio.fixt | High | 4/15/2026 |
| v1.4.0a0 | # [1.4.0a0](https://github.com/pytest-dev/pytest-asyncio/tree/1.4.0a0) - 2026-03-25 ## Added - Added the `pytest_asyncio_loop_factories` hook to parametrize asyncio tests with custom event loop factories. The hook now returns a mapping of factory names to loop factories, and `pytest.mark.asyncio(loop_factories=[...])` can be used to select a subset of configured factories per test. ([#1164](https://github.com/pytest-dev/pytest-asyncio/issues/1164)) ## Changed - Improved th | High | 4/15/2026 |
| v1.3.0 | # [1.3.0](https://github.com/pytest-dev/pytest-asyncio/tree/1.3.0) - 2025-11-10 ## Removed - Support for Python 3.9 ([#1278](https://github.com/pytest-dev/pytest-asyncio/issues/1278)) ## Added - Support for pytest 9 ([#1279](https://github.com/pytest-dev/pytest-asyncio/issues/1279)) ## Notes for Downstream Packagers - Tested Python versions include free threaded Python 3.14t ([#1274](https://github.com/pytest-dev/pytest-asyncio/issues/1274)) - Tests are run in the same | Low | 11/10/2025 |
| v1.2.0 | # [1.2.0](https://github.com/pytest-dev/pytest-asyncio/tree/1.2.0) - 2025-09-12 ## Added - `--asyncio-debug` CLI option and `asyncio_debug` configuration option to enable asyncio debug mode for the default event loop. ([#980](https://github.com/pytest-dev/pytest-asyncio/issues/980)) - A `pytest.UsageError` for invalid configuration values of `asyncio_default_fixture_loop_scope` and `asyncio_default_test_loop_scope`. ([#1189](https://github.com/pytest-dev/pytest-asyncio/issues/1189)) | Low | 9/12/2025 |
| v1.1.1 | # [v1.1.1](https://github.com/pytest-dev/pytest-asyncio/tree/v1.1.1) - 2025-09-12 ## Notes for Downstream Packagers \- Addresses a build problem with setuptoos-scm \>= 9 caused by invalid setuptools-scm configuration in pytest-asyncio. ([#1192](https://github.com/pytest-dev/pytest-asyncio/issues/1192)) | Low | 9/12/2025 |
| v1.1.0 | # Added - Propagation of ContextVars from async fixtures to other fixtures and tests on Python 3.10 and older ([#127](https://github.com/pytest-dev/pytest-asyncio/issues/127)) - Cancellation of tasks when the `loop_scope` ends ([#200](https://github.com/pytest-dev/pytest-asyncio/issues/200)) - Warning when the current event loop is closed by a test # Fixed - Error about missing loop when calling functions requiring a loop in the `finally` clause of a task ([#878](https://github.com/ | Low | 7/16/2025 |
| v1.1.0a1 | # [1.1.0a1](https://github.com/pytest-dev/pytest-asyncio/tree/1.1.0a1) - 2025-06-30 ## Added - Propagation of ContextVars from async fixtures to other fixtures and tests on Python 3.10 and older ([#127](https://github.com/pytest-dev/pytest-asyncio/issues/127)) - Cancellation of tasks when the *loop_scope* ends ([#200](https://github.com/pytest-dev/pytest-asyncio/issues/200)) - Warning when the current event loop is closed by a test ## Fixed - Error about missing loop when callin | Low | 6/30/2025 |
| v1.0.0 | # [1.0.0](https://github.com/pytest-dev/pytest-asyncio/tree/1.0.0) - 2025-05-26 ## Removed - The deprecated *event_loop* fixture. ([#1106](https://github.com/pytest-dev/pytest-asyncio/issues/1106)) ## Added - Prelimiary support for Python 3.14 ([#1025](https://github.com/pytest-dev/pytest-asyncio/issues/1025)) ## Changed - Scoped event loops (e.g. module-scoped loops) are created once rather than per scope (e.g. per module). This reduces the number of fixtures and s | Low | 5/26/2025 |
| v1.0.0a1 | # [1.0.0a1](https://github.com/pytest-dev/pytest-asyncio/tree/1.0.0a1) - 2025-05-09 ## Removed - The deprecated *event_loop* fixture. ([#1106](https://github.com/pytest-dev/pytest-asyncio/issues/1106)) ## Added - Prelimiary support for Python 3.14 ([#1025](https://github.com/pytest-dev/pytest-asyncio/issues/1025)) ## Changed - Scoped event loops (e.g. module-scoped loops) are created once rather than per scope (e.g. per module). This reduces the number of fixtures a | Low | 5/9/2025 |
| v0.26.0 | - Adds configuration option that sets default event loop scope for all tests [#793](https://github.com/pytest-dev/pytest-asyncio/issues/793) - Improved type annotations for `pytest_asyncio.fixture` [#1045](https://github.com/pytest-dev/pytest-asyncio/pull/1045) - Added `typing-extensions` as additional dependency for Python `<3.10` [#1045](https://github.com/pytest-dev/pytest-asyncio/pull/1045) | Low | 3/25/2025 |
| v0.25.3 | - Avoid errors in cleanup of async generators when event loop is already closed [#1040](https://github.com/pytest-dev/pytest-asyncio/issues/1040) | Low | 1/28/2025 |
| v0.25.2 | - Call `loop.shutdown_asyncgens()` before closing the event loop to ensure async generators are closed in the same manner as `asyncio.run` does [#1034](https://github.com/pytest-dev/pytest-asyncio/pull/1034) | Low | 1/8/2025 |
| v0.25.1 | - Fixes an issue that caused a broken event loop when a function-scoped test was executed in between two tests with wider loop scope [#950](https://github.com/pytest-dev/pytest-asyncio/issues/950) - Improves test collection speed in auto mode [#1020](https://github.com/pytest-dev/pytest-asyncio/pull/1020) - Corrects the warning that is emitted upon redefining the event_loop fixture | Low | 1/2/2025 |
| v0.25.0 | # 0.25.0 (2024-12-13) - Deprecated: Added warning when asyncio test requests async `@pytest.fixture` in strict mode. This will become an error in a future version of flake8-asyncio. [#979](https://github.com/pytest-dev/pytest-asyncio/pull/979) - Updates the error message about _pytest.mark.asyncio_'s _scope_ keyword argument to say _loop_scope_ instead. [#1004](https://github.com/pytest-dev/pytest-asyncio/pull/1004) - Verbose log displays correct parameter name: asyncio_default_fixture_loop_s | Low | 12/13/2024 |
| v0.24.0 | # 0.24.0 (2024-08-22) - BREAKING: Updated minimum supported pytest version to v8.2.0 - Adds an optional _loop_scope_ keyword argument to _pytest.mark.asyncio_. This argument controls which event loop is used to run the marked async test. [#706](https://github.com/pytest-dev/pytest-asyncio/issues/706), [#871](https://github.com/pytest-dev/pytest-asyncio/pull/871) - Deprecates the optional _scope_ keyword argument to _pytest.mark.asyncio_ for API consistency with `pytest_asyncio.fixture`. Users | Low | 8/22/2024 |
| v0.24.0a1 | # 0.24.0 (UNRELEASED) - BREAKING: Updated minimum supported pytest version to v8.2.0 - Adds an optional _loop_scope_ keyword argument to _pytest.mark.asyncio_. This argument controls which event loop is used to run the marked async test. [#706](https://github.com/pytest-dev/pytest-asyncio/issues/706), [#871](https://github.com/pytest-dev/pytest-asyncio/pull/871) - Deprecates the optional _scope_ keyword argument to _pytest.mark.asyncio_ for API consistency with `pytest_asyncio.fixture`. Use | Low | 8/9/2024 |
| v0.24.0a0 | # 0.24.0 (UNRELEASED) - Adds an optional *loop_scope* keyword argument to *pytest.mark.asyncio*. This argument controls which event loop is used to run the marked async test. [#706](https://github.com/pytest-dev/pytest-asyncio/issues/706), [#871](https://github.com/pytest-dev/pytest-asyncio/issues/871) - Deprecates the optional *scope* keyword argument to *pytest.mark.asyncio* for API consistency with ``pytest_asyncio.fixture``. Users are encouraged to use the *loop_scope* keyword argument, | Low | 7/30/2024 |
| v0.23.8 | # 0.23.8 (2024-07-17) - Fixes a bug that caused duplicate markers in async tests [#813](https://github.com/pytest-dev/pytest-asyncio/issues/813) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytest-asyncio currently assumes that async fixture scope is correlated with the new event loop scope. This prevents fixtur | Low | 7/17/2024 |
| v0.23.7 | # 0.23.7 (2024-05-19) - Silence deprecation warnings about unclosed event loops that occurred with certain CPython patch releases [#817](https://github.com/pytest-dev/pytest-asyncio/pull/817) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytest-asyncio currently assumes that async fixture scope is correlated wi | Low | 5/19/2024 |
| v0.21.2 | # 0.21.2 (2024-04-29) - Fix compatibility with pytest 8.2. Backport of [#800](https://github.com/pytest-dev/pytest-asyncio/pull/800) to pytest-asyncio v0.21 for users who are unable to upgrade to a more recent version (see [#706](https://github.com/pytest-dev/pytest-asyncio/pull/706) | Low | 4/29/2024 |
| v0.23.6 | # 0.23.6 (2024-03-19) - Fix compatibility with pytest 8.2 [#800](https://github.com/pytest-dev/pytest-asyncio/pull/800) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytest-asyncio currently assumes that async fixture scope is correlated with the new event loop scope. This prevents fixtures from being evaluated | Low | 3/19/2024 |
| v0.23.5.post1 | # 0.23.5 (2024-02-09) - Declare compatibility with pytest 8 [#737](https://github.com/pytest-dev/pytest-asyncio/issues/737) - Fix typing errors with recent versions of mypy [#769](https://github.com/pytest-dev/pytest-asyncio/issues/769) - Prevent DeprecationWarning about internal use of `asyncio.get_event_loop()` from affecting test cases [#757](https://github.com/pytest-dev/pytest-asyncio/issues/757) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each ite | Low | 3/8/2024 |
| v0.23.5 | # 0.23.5 (2024-02-09) - Declare compatibility with pytest 8 [#737](https://github.com/pytest-dev/pytest-asyncio/issues/737) - Fix typing errors with recent versions of mypy [#769](https://github.com/pytest-dev/pytest-asyncio/issues/769) - Prevent DeprecationWarning about internal use of `asyncio.get_event_loop()` from affecting test cases [#757](https://github.com/pytest-dev/pytest-asyncio/issues/757) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each ite | Low | 2/9/2024 |
| v0.23.5a0 | # 0.23.5 (UNRELEASED) - Declare compatibility with pytest 8 [#737](https://github.com/pytest-dev/pytest-asyncio/issues/737) - Fix typing errors with recent versions of mypy [#769](https://github.com/pytest-dev/pytest-asyncio/issues/769) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytest-asyncio currently assum | Low | 2/6/2024 |
| v0.23.4 | # 0.23.4 (2024-01-28) - pytest-asyncio no longer imports additional, unrelated packages during test collection [#729](https://github.com/pytest-dev/pytest-asyncio/issues/729) - Addresses further issues that caused an internal pytest error during test collection - Declares incompatibility with pytest 8 [#737](https://github.com/pytest-dev/pytest-asyncio/issues/737) | Low | 1/28/2024 |
| v0.23.4a2 | # 0.23.4 (UNRELEASED) - pytest-asyncio no longer imports additional, unrelated packages during test collection [#729](https://github.com/pytest-dev/pytest-asyncio/issues/729) - Addresses further issues that caused an internal pytest error during test collection ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytes | Low | 1/16/2024 |
| v0.23.4a1 | # 0.23.4 (UNRELEASED) - pytest-asyncio no longer imports additional, unrelated packages during test collection [#729](https://github.com/pytest-dev/pytest-asyncio/issues/729) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytest-asyncio currently assumes that async fixture scope is correlated with the new event lo | Low | 1/10/2024 |
| v0.23.4a0 | # 0.23.4 (UNRELEASED) - pytest-asyncio no longer imports additional, unrelated packages during test collection [#729](https://github.com/pytest-dev/pytest-asyncio/issues/729) ## Known issues As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytest-asyncio currently assumes that async fixture scope is correlated with the new event lo | Low | 1/9/2024 |
| v0.23.3 | # 0.23.3 (2024-01-01) - Fixes a bug that caused event loops to be closed prematurely when using async generator fixtures with class scope or wider in a function-scoped test [#706](https://github.com/pytest-dev/pytest-asyncio/issues/706) - Fixes various bugs that caused an internal pytest error during test collection [#711](https://github.com/pytest-dev/pytest-asyncio/issues/711) [#713](https://github.com/pytest-dev/pytest-asyncio/issues/713) [#719](https://github.com/pytest-dev/pytest-asynci | Low | 1/1/2024 |
| v0.23.3a0 | # 0.23.3 (UNRELEASED) - Fixes a bug that caused event loops to be closed prematurely when using async generator fixtures with class scope or wider in a function-scoped test [#708](https://github.com/pytest-dev/pytest-asyncio/issues/708) - Fixes a bug that caused an internal pytest error when using unittest.SkipTest in a module [#711](https://github.com/pytest-dev/pytest-asyncio/issues/711) | Low | 12/9/2023 |
| v0.23.2 | # 0.23.2 (2023-12-04) - Fixes a bug that caused an internal pytest error when collecting .txt files [#703](https://github.com/pytest-dev/pytest-asyncio/issues/703) | Low | 12/4/2023 |
| v0.23.1 | # 0.23.1 (2023-12-03) - Fixes a bug that caused an internal pytest error when using module-level skips [#701](https://github.com/pytest-dev/pytest-asyncio/issues/701) | Low | 12/3/2023 |
| v0.23.0 | This release is backwards-compatible with v0.21. Changes are non-breaking, unless you upgrade from v0.22. - BREAKING: The *asyncio_event_loop* mark has been removed. Event loops with class, module, package, and session scopes can be requested via the *scope* keyword argument to the *asyncio* mark. - Introduces the *event_loop_policy* fixture which allows testing with non-default or multiple event loops [#662](https://github.com/pytest-dev/pytest-asyncio/pull/662) - | Low | 12/3/2023 |
| v0.23.0b0 | # 0.23.0 (UNRELEASED) This release is backwards-compatible with v0.21. Changes are non-breaking, unless you upgrade from v0.22. * BREAKING: The _asyncio_event_loop_ mark has been removed. Event loops with class, module, package, and session scopes can be requested via the _scope_ keyword argument to the _asyncio_ mark. * Introduces the _event_loop_policy_ fixture which allows testing with non-default or multiple event loops [#662](https://github.com/pytest-dev/pytest-asyncio/pull/662) | Low | 11/27/2023 |
| v0.23.0a1 | # 0.23.0 (UNRELEASED) This release is backwards-compatible with v0.21. Changes are non-breaking, unless you upgrade from v0.22. * BREAKING: The _asyncio_event_loop_ mark has been removed. Event loops with class, module, package, and session scopes can be requested via the _scope_ keyword argument to the _asyncio_ mark. * Introduces the _event_loop_policy_ fixture which allows testing with non-default or multiple event loops [#662](https://github.com/pytest-dev/pytest-asyncio/pull/662) | Low | 11/16/2023 |
| v0.23.0a0 | # 0.23.0 (UNRELEASED) This release is backwards-compatible with v0.21. Changes are non-breaking, unless you upgrade from v0.22. * BREAKING: The _asyncio_event_loop_ mark has been removed. Event loops with class, module, package, and session scopes can be requested via the _scope_ keyword argument to the _asyncio_ mark. * Introduces the _event_loop_policy_ fixture which allows testing with non-default or multiple event loops [#662](https://github.com/pytest-dev/pytest-asyncio/pull/662) | Low | 11/12/2023 |
| v0.22.0 | *This release deprecated event loop overrides, but didn't provide adequate replacement functionality for all relevant use cases. As such, the release was yanked from PyPI.* # 0.22.0 (2023-10-31) * Class-scoped and module-scoped event loops can be requested via the _asyncio_event_loop_ mark. [#620](https://github.com/pytest-dev/pytest-asyncio/pull/620) * Deprecate redefinition of the _event_loop_ fixture. [#587](https://github.com/pytest-dev/pytest-asyncio/issues/531) Users requiring a | Low | 10/31/2023 |
| v0.21.1 | # 0.21.1 (2023-07-12) * Output a proper error message when an invalid `asyncio_mode` is selected. * Extend warning message about unclosed event loops with additional possible cause. #531 * Previously, some tests reported "skipped" or "xfailed" as a result. Now all tests report a "success" result. | Low | 7/12/2023 |
| v0.21.0 | # 0.21.0 (23-03-19) * Drop compatibility with pytest 6.1. Pytest-asyncio now depends on pytest 7.0 or newer. * pytest-asyncio cleans up any stale event loops when setting up and tearing down the event_loop fixture. This behavior has been deprecated and pytest-asyncio emits a DeprecationWarning when tearing down the event_loop fixture and current event loop has not been closed. | Low | 3/19/2023 |
| v0.20.3 | --- title: 'pytest-asyncio' --- [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [](https://pypi.python.org/pypi/pytest-asyncio) [](https://github.com/pytest-dev/pytest-asyncio/actions?workflow=CI) [](https://codecov.io/gh/pytest-dev/pytest-asyncio) [