skillfed

pytest-twisted

A twisted plugin for pytest.

pytest-twisted v1.14.3 285.9K downloads/30d#8,052 on PyPI46
Permissive license Active released

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-twisted

uv

uv add pytest-twisted

poetry

poetry add pytest-twisted

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing

Tags

pytest twisted testingtest twisted deferredasync twisted testspytest async reactortwisted framework testingdeferred test pluginpytest twisted integration
twisted-testingasync-reactordeferred-support

More Testing packages