Skip to main content
Authors:

Ralf Schmitt <ralf@systemexit.de>

Version:
1.5
Date:
2014-02-04
Download:

https://pypi.python.org/pypi/pytest-twisted#downloads

Code:

https://github.com/schmir/pytest-twisted

pytest-twisted is a plugin for pytest, which allows to test code, which uses the twisted framework. test functions can return Deferred objects and pytest will wait for their completion with this plugin.

Installation

Install the plugin with:

pip install pytest-twisted

Using the plugin

The plugin must be enabled. This can be done in the following ways:

  1. Run py.test with the –twisted command line option

  2. Put the following into conftest.py:

    pytest_plugins = "pytest_twisted"
  3. Put the following into pytest.ini:

    [pytest]
    twisted = 1

inlineCallbacks

Using twisted.internet.defer.inlineCallbacks as a decorator for test functions, which take funcargs, does not work. Please use pytest.inlineCallbacks instead:

@pytest.inlineCallbacks
def test_some_stuff(tmpdir):
    res = yield threads.deferToThread(os.listdir, tmpdir.strpath)
    assert res == []

Waiting for deferreds in fixtures

pytest.blockon allows fixtures to wait for deferreds:

@pytest.fixture
def val():
    d = defer.Deferred()
    reactor.callLater(1.0, d.callback, 10)
    return pytest.blockon(d)

The twisted greenlet

Some libraries (e.g. corotwine) need to know the greenlet, which is running the twisted reactor. It’s available from the twisted_greenlet funcarg. The following code can be used to make corotwine work with pytest-twisted:

@pytest.fixture(scope="session", autouse=True)
def set_MAIN(request, twisted_greenlet):
    from corotwine import protocol
    protocol.MAIN = twisted_greenlet

That’s all.

Release files for pytest-twisted 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-twisted 1.5
File Size Uploaded
pytest-twisted-1.5.zip 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-twisted 1.5
File Interpreter ABI Platform
pytest_twisted-1.5-py27-none-any.whl Python 2.7 none any Details

Total release size: 14.2 kB

Release files / pytest-twisted-1.5.zip

Download URL pytest-twisted-1.5.zip
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d0dc887f15f4d0ade882e56590a3cce95b70fd0687ba8d2428a6364f3288d87e
BLAKE2b-256 checksum
How to use checksums
74660c64463ed9501c09e4c79bc924743e2e4cd02eb4498d492b5e3c81911198
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pytest_twisted-1.5-py27-none-any.whl

Download URL pytest_twisted-1.5-py27-none-any.whl
Size 5.6 kB
Tags Python 2.7
SHA-256 checksum
How to use checksums
c499814ed80e2aad809135d984383c92783d25c350a2e0eeddbdb82477ad72f8
BLAKE2b-256 checksum
How to use checksums
0c35b745739c1d17e1758082fd4af9c265daaa2b6cc2d12c0480e17805195e61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.14.3

2 release files

1.14.2

2 release files

1.14.1

2 release files

1.14.0

2 release files

1.13.4

2 release files

1.13.3

2 release files

1.13.2

2 release files

1.13.1

2 release files

1.13

2 release files

1.12

2 release files

1.11

2 release files

1.10

1 release file

1.9

1 release file

1.8

1 release file

1.7.1

1 release file

1.7

1 release file

1.6

1 release file

This release

1.5 This release

2 release files

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page