Skip to main content

A py.test plugin providing fixtures and markers to simplify testing of asynchronous tornado applications.

Project description

https://travis-ci.org/eugeniy/pytest-tornado.svg?branch=master https://coveralls.io/repos/eugeniy/pytest-tornado/badge.svg

A py.test plugin providing fixtures and markers to simplify testing of asynchronous tornado applications.

Installation

pip install pytest-tornado

Example

import pytest
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

@pytest.fixture
def app():
    return application

@pytest.mark.gen_test
def test_hello_world(http_client, base_url):
    response = yield http_client.fetch(base_url)
    assert response.code == 200

Running tests

py.test

Fixtures

io_loop

creates an instance of the tornado.ioloop.IOLoop for each test case

http_port

get a port used by the test server

base_url

get an absolute base url for the test server, for example, http://localhost:59828

http_server

start a tornado HTTP server, you must create an app fixture, which returns the tornado.web.Application to be tested

http_client

get an asynchronous HTTP client

Show fixtures provided by the plugin:

py.test --fixtures

Markers

A gen_test marker lets you write a coroutine-style tests used with the tornado.gen module:

@pytest.mark.gen_test
def test_tornado(http_client):
    response = yield http_client.fetch('http://www.tornadoweb.org/')
    assert response.code == 200

Marked tests will time out after 5 seconds. The timeout can be modified by setting an ASYNC_TEST_TIMEOUT environment variable, --async-test-timeout command line argument or a marker argument.

@pytest.mark.gen_test(timeout=5)
def test_tornado(http_client):
    yield http_client.fetch('http://www.tornadoweb.org/')

Show markers provided by the plugin:

py.test --markers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-tornado-0.4.4.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

pytest_tornado-0.4.4-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-tornado-0.4.4.tar.gz.

File metadata

File hashes

Hashes for pytest-tornado-0.4.4.tar.gz
Algorithm Hash digest
SHA256 5882779d3cf0f6147b08bbda7d8781af63b71ea967c8370e508b57d92986e2a5
MD5 9f82cf83473577d17c5d54f73d31d96c
BLAKE2b-256 d643f3eb339040e8e59c156b8172dd698ffb13c995461c3de729bdb12e5eaf56

See more details on using hashes here.

Provenance

File details

Details for the file pytest_tornado-0.4.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_tornado-0.4.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d02097a97b3e45534f4656fd9a5a806eb89344c732e4e31fe9c322471da989da
MD5 2228cd06faa55df1aa21da41a52e0076
BLAKE2b-256 ee69ef9c98cccbfe543ecc6db58f65df1bd47e2c112223ef421bc9cafd2bff1e

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page