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.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | pytest-dev/pytest-asyncio |
| Owner | pytest-dev |
| Primary language | Python |
| License | Apache-2.0 — OSI-approved |
| Stars | 1.6k |
| Forks | 189 |
| Open issues | 51 |
| Latest release | v1.4.0 (2026-05-26) |
| Last updated | 2026-07-06 |
| Source | https://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.
Get the pytest-asyncio source
Clone the repository and explore it locally.
git clone https://github.com/pytest-dev/pytest-asyncio.gitcd pytest-asyncio# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
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.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
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.
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.coRelated 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?
Can I mix async and sync tests in the same file?
What Python versions are supported?
How do I run pytest-asyncio tests in CI?
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.