DEV.co
Open-Source Testing · pytest-dev

pytest-asyncio

pytest-asyncio is a pytest plugin that enables testing of asynchronous Python code using asyncio. It allows developers to write async test functions with the @pytest.mark.asyncio decorator, simplifying the testing of async libraries and applications.

Source: GitHub — github.com/pytest-dev/pytest-asyncio
1.6k
GitHub stars
189
Forks
Python
Primary language
Apache-2.0
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorypytest-dev/pytest-asyncio
Ownerpytest-dev
Primary languagePython
LicenseApache-2.0 — OSI-approved
Stars1.6k
Forks189
Open issues51
Latest releasev1.4.0 (2026-05-26)
Last updated2026-07-06
Sourcehttps://github.com/pytest-dev/pytest-asyncio

What pytest-asyncio is

A pytest plugin providing first-class support for coroutine test functions, allowing developers to await asyncio calls directly within test code. It integrates with pytest's discovery and execution model to manage event loops and async fixtures.

Quickstart

Get the pytest-asyncio source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/pytest-dev/pytest-asyncio.gitcd pytest-asyncio# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Testing asyncio-based libraries and frameworks

Ideal for projects built on asyncio (aiohttp, FastAPI, SQLAlchemy async, etc.) where test code must await async functions and coroutines naturally.

CI/CD pipelines for async Python applications

Streamlines continuous integration for async microservices and backend systems by enabling pytest-native async test execution without boilerplate event loop management.

Development-phase validation of async code

Supports rapid iteration and debugging of async code during development, with standard pytest tooling (fixtures, markers, parametrization) applied to async tests.

Implementation considerations

  • Requires explicit @pytest.mark.asyncio decorator on async test functions; unmarked coroutines will fail at collection time.
  • Event loop scope and fixture lifecycle differ from synchronous tests; review documentation on fixture scoping (function, module, session) for async context.
  • Async fixture definitions use async def; ensure proper teardown/cleanup to avoid resource leaks in long-running test suites.
  • Plugin auto-discovery requires no explicit configuration if installed via pip, but pytest.ini or pyproject.toml may be needed for custom event loop policies.
  • Standard pytest plugins and parametrization work with async tests, but some third-party plugins may have compatibility constraints—verify before adoption.

When to avoid it — and what to weigh

  • Synchronous-only test suites — If your codebase contains only synchronous code, pytest-asyncio adds unnecessary overhead and complexity. Standard pytest is sufficient.
  • unittest-based async test classes — The plugin does not support async test classes subclassing unittest.TestCase. Use unittest.IsolatedAsyncioTestCase or switch to pytest-style tests instead.
  • Projects requiring alternative async backends — pytest-asyncio is tightly coupled to Python's standard asyncio library. Projects using Trio, Curio, or other async runtimes will need alternative test runners.
  • Minimal or offline-only environments — Adds a runtime dependency to your test infrastructure. Air-gapped deployments must pre-stage the package and its transitive dependencies.

License & commercial use

Licensed under Apache License 2.0 (Apache-2.0), a permissive OSI-approved license permitting commercial use, modification, and redistribution with attribution.

Apache 2.0 is a permissive license allowing commercial use of pytest-asyncio in proprietary and open-source projects. No license fees or restrictions apply. Standard disclaimers of warranty apply; review the full license text at https://github.com/pytest-dev/pytest-asyncio/blob/main/LICENSE for indemnification and liability terms.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

No specific security vulnerabilities disclosed in the provided data. As a test-time-only plugin, pytest-asyncio has limited production attack surface. Standard Python package supply-chain practices apply: verify package integrity via PyPI hash, pin versions, and monitor security advisories. Event loop and fixture handling should not expose secrets in test output; review log redaction in your CI configuration.

Alternatives to consider

unittest.IsolatedAsyncioTestCase (stdlib)

Built into Python 3.8+; no external dependency. Suitable for projects already using unittest. Less tightly integrated with pytest ecosystem.

anyio.from_thread (anyio library)

Broader async runtime support (asyncio, Trio, Curio). Requires manual event loop management and different test structure; more verbose but framework-agnostic.

asynctest (third-party library)

Older async testing utility; supports mock.AsyncMock and async context managers. Less actively maintained than pytest-asyncio; mentioned in README as alternative for unittest users.

Software development agency

Build on pytest-asyncio with DEV.co software developers

Install pytest-asyncio with pip and start writing async tests today. Review the documentation for fixture scoping and event loop configuration best practices for your use case.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

pytest-asyncio FAQ

Do I need to manually manage the event loop in my tests?
No. pytest-asyncio automatically creates and manages event loops per test function (or module/session scope if configured). You only mark tests with @pytest.mark.asyncio and await normally.
Can I mix async and sync tests in the same file?
Yes. Async tests must be marked with @pytest.mark.asyncio; unmarked synchronous tests run normally. pytest handles both in the same suite.
What Python versions are supported?
The README indicates broad Python version support via a badge; consult PyPI or GitHub releases for exact version matrix. Minimum version typically Python 3.6+.
How do I run pytest-asyncio tests in CI?
No special configuration needed beyond pip install pytest-asyncio. Run standard pytest commands; CI workflows remain unchanged. Ensure Python environment and dependencies are in place.

Software development & web development with DEV.co

From first prototype to production, DEV.co delivers software development services around tools like pytest-asyncio. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source testing and beyond.

Ready to test your async code?

Install pytest-asyncio with pip and start writing async tests today. Review the documentation for fixture scoping and event loop configuration best practices for your use case.