pytest-twisted
A twisted plugin for pytest.
What it is and what it does
pytest-twisted is a pytest plugin that bridges the gap between pytest's synchronous test model and Twisted's asynchronous Deferred-based concurrency. It automatically installs a Twisted reactor before tests run and allows test functions to return Deferred objects, which the plugin waits for rather than treating as test failures. The plugin also provides decorators and fixtures for async/await syntax, inline callbacks, and greenlet access, making it possible to write Twisted tests using pytest's standard fixture and assertion machinery.
The plugin supports multiple reactor implementations (default, asyncio, qt5reactor) and integrates with pytest's fixture system, allowing fixtures to also work with async code. It handles the complexity of reactor lifecycle management so developers can focus on testing their Twisted application logic rather than managing event loop setup and teardown.
Use it for:
- Testing Twisted-based network services and protocol implementations that use Deferred callbacks
- Writing async test fixtures that need to wait for Twisted operations before providing test data
- Testing Twisted code with async/await syntax using ensureDeferred or async_fixture decorators
- Integrating Twisted application tests into a pytest-based test suite alongside synchronous tests
- Testing libraries that depend on greenlets and need access to the reactor greenlet context
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that enables testing of Twisted-based asynchronous code by allowing test functions to return Deferred objects and waiting for their completion.
Yes, if you are testing Twisted code. The plugin is actively maintained, has no known vulnerabilities, and low install friction. It solves a real problem—running Twisted's asynchronous code within pytest's synchronous test framework—and is the standard tool for this task. Install it if Twisted is part of your project; skip it otherwise.
Install
pytest-twisted on PyPI
pip
pip install pytest-twisteduv
uv add pytest-twistedpoetry
poetry add pytest-twistedInstalling pytest-twisted
Before you install
Low install friction with a pure-Python wheel distribution. Actively maintained with recent commits and stable status; last release was 703 days ago but the repository shows ongoing activity.
License in practice
Permissive license treatment means you can use this plugin in commercial and proprietary projects without significant legal constraints.
Quickstart
pip install pytest-twisted
# In conftest.py or test file:
import pytest_twisted
from twisted.internet import defer
@pytest_twisted.inlineCallbacks
def test_deferred_operation():
result = yield defer.succeed(42)
assert result == 42
Requires Twisted to be installed separately; on Windows with Python 3.8+, asyncio reactor requires explicit selector loop configuration as documented in the package description.
Verify before relying
- Whether Python 2.7 support remains practically tested or is maintained for compatibility only
- Current state of Windows + Python 3.8+ asyncio reactor compatibility beyond the documented workaround
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — greenlet, pytest, decorator |
| Maintenance | actively maintained — 703 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 285,869/month — #8,052 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_twisted-1.14.3-py2.py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
TwistedTwisted is an event-driven networking framework…
permissive · top 5,000 on PyPI
txaiotxaio provides a compatibility layer that lets…
permissive · top 5,000 on PyPI
treqtreq is a high-level HTTP client library for…
permissive · top 15,000 on PyPI
crochetCrochet lets you call Twisted asynchronous code…
permissive · top 15,000 on PyPI
pytest-tornadoA pytest plugin that provides fixtures and…
permissive · top 15,000 on PyPI
pytest-grpcA pytest plugin that provides fixtures to write…
permissive · top 15,000 on PyPI
pytest-run-parallelA pytest plugin that runs test functions…
permissive · top 15,000 on PyPI
localstack-twistedA LocalStack-optimized distribution of Twisted…
permissive · top 15,000 on PyPI
pytest-tornasyncA pytest plugin that runs native async test…
permissive · top 15,000 on PyPI