pytest-tornado

0.8.1 · active · verified Thu Apr 16

pytest-tornado is a plugin for the Pytest testing framework that simplifies testing asynchronous Tornado applications. It provides a set of fixtures and markers designed to integrate Tornado's asynchronous features seamlessly into pytest tests. The current version is 0.8.1, released on June 17, 2020, and the project has an infrequent release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to test a simple Tornado web application using `pytest-tornado`. It defines a Tornado application, provides it via a `pytest` fixture named `app`, and then uses the `@pytest.mark.gen_test` marker along with `http_client` and `base_url` fixtures to perform an asynchronous HTTP request and assert the response.

import pytest
import tornado.web
import tornado.httpclient

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
async def test_hello_world(http_client, base_url):
    response = await http_client.fetch(base_url)
    assert response.code == 200
    assert response.body == b"Hello, world"

# To run: `pytest your_test_file.py`

view raw JSON →