GithubHelp home page GithubHelp logo

kiminewt / pytest-tornado Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eugeniy/pytest-tornado

1.0 2.0 0.0 120 KB

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

License: Apache License 2.0

Python 100.00%

pytest-tornado's Introduction

pytest-tornado

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

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

pytest-tornado's People

Contributors

djgilcrease avatar eugeniy avatar s0undt3ch avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.