Repolode
pytest-dev

pytest-dev/pytest-asyncio

A pytest plugin that lets test functions be coroutines, so you can await asyncio code directly inside tests.

Stars
1,669
Forks
217
Open issues
53
Last commit
23 hours ago

What is it?

pytest-asyncio is a plugin for pytest that adds support for testing code built on Python's asyncio library. It allows test functions to be declared as coroutines, so asynchronous calls can be awaited directly inside a test instead of being wrapped in manual event loop code.

Tests are marked with the asyncio marker, and pytest runs them as regular test items. The project's documentation covers configuration options and how to manage event loops and async fixtures. Installation is a single pip command, and pytest picks up the plugin automatically once it is installed.

The plugin does not support test classes that subclass the standard unittest library. For those cases, the project points users to unittest.IsolatedAsyncioTestCase or async-aware frameworks.

Key features

  • 01Run coroutine test functions marked with the asyncio marker.
  • 02Await asynchronous code directly inside test bodies.
  • 03Works as a standard pytest plugin installed with pip.
  • 04Documented configuration and event loop management.

Use cases

  • Testing async web service handlers or clients built on asyncio.
  • Writing integration tests that call async database or network libraries.
  • Testing async fixtures shared across a pytest test suite.

Quick start

  1. 1

    Install pytest-asyncio with pip

    pip install pytest-asyncio

Things to know

  • Test classes subclassing unittest are not supported; use unittest.IsolatedAsyncioTestCase instead.

In collections

Topics

FAQ

What is pytest-asyncio?
A pytest plugin that lets test functions be coroutines, so you can await asyncio code directly inside tests. pytest-asyncio is a plugin for pytest that adds support for testing code built on Python's asyncio library. It allows test functions to be declared as coroutines, so asynchronous calls can be awaited directly inside a test instead of being wrapped in manual event loop code.
Is pytest-asyncio free to use? What license does it have?
pytest-asyncio is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is pytest-asyncio still maintained?
Actively maintained. The last commit to pytest-asyncio was on Nov 6, 2026.
What can I use pytest-asyncio for?
Testing async web service handlers or clients built on asyncio. Writing integration tests that call async database or network libraries. Testing async fixtures shared across a pytest test suite.
How do I install pytest-asyncio?
Install pytest-asyncio with pip: pip install pytest-asyncio
Where can I get pytest-asyncio?
The source code and installation instructions are on GitHub: https://github.com/pytest-dev/pytest-asyncio

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects