Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

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

Project Description

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


pip install pytest-tornado


import pytest
import tornado.web

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

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

def app():
    return application

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

Running tests



creates an instance of the tornado.ioloop.IOLoop for each test case
get a port used by the test server
get an absolute base url for the test server, for example, http://localhost:59828
start a tornado HTTP server, you must create an app fixture, which returns the tornado.web.Application to be tested
get an asynchronous HTTP client

Show fixtures provided by the plugin:

py.test --fixtures


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

def test_tornado(http_client):
    response = yield http_client.fetch('')
    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.

def test_tornado(http_client):
    yield http_client.fetch('')

The mark can also receive a run_sync flag, which if turned off will, instead of running the test synchronously, will add it as a coroutine and run the IOLoop (until the timeout). For instance, this allows to test things on both a client and a server at the same time.

def test_tornado(http_server, http_client):
    response = yield http_client.fetch('http://localhost:5555/my_local_server_test/')
    assert response.body == 'Run on the same IOLoop!'

Show markers provided by the plugin:

py.test --markers

Release History

This version
History Node


Download Files

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

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(7.2 kB) Copy SHA256 Hash SHA256
py2.py3 Wheel Feb 22, 2016
(4.7 kB) Copy SHA256 Hash SHA256
Source Feb 22, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting