Testing tornado web application in any testing libraries.
Project description
Tornado-Tester
==============
Testing tool of tornado web for any testing libraries.
Contextual Tester
-----------------
You can use testing tool by using 'with' statement. ::
import unittest
from tornado_tester import gen_test, Tester
from yourapplication import app
class Test(unittest.TestCase):
@gen_test
def test_app():
with Tester(app) as tester:
response = yield tester.http_client(tester.url_for('/hello'))
...
By using :meth:`url_for` you can make URL with current HTTP server's address.
And you can use it for py.test like. ::
import pytest
from tornado_tester import gen_test, Tester
from yourapplication import app
@pytest.fixture
def tester(request):
tester = Tester(app)
tester.setup()
request.addfinalizer(tester.teardown)
return tester
@gen_test
def test_app(tester):
response = yield tester.http_client(tester.url_for('/hello'))
...
.. warning::
You can't use multiple Testers in one gen_test by default.
You should provide a shared I/O loop to use multiple tester. ::
import pytest
from tornado.ioloop import IOLoop
from tornado_tester import gen_test, Tester
from yourapplication import app
@gen_test
def test_app():
loop = IOLoop()
tester1 = Tester(app, io_loop=loop)
tester2 = Tester(app, io_loop=loop)
with tester1:
...
with tester2:
...
==============
Testing tool of tornado web for any testing libraries.
Contextual Tester
-----------------
You can use testing tool by using 'with' statement. ::
import unittest
from tornado_tester import gen_test, Tester
from yourapplication import app
class Test(unittest.TestCase):
@gen_test
def test_app():
with Tester(app) as tester:
response = yield tester.http_client(tester.url_for('/hello'))
...
By using :meth:`url_for` you can make URL with current HTTP server's address.
And you can use it for py.test like. ::
import pytest
from tornado_tester import gen_test, Tester
from yourapplication import app
@pytest.fixture
def tester(request):
tester = Tester(app)
tester.setup()
request.addfinalizer(tester.teardown)
return tester
@gen_test
def test_app(tester):
response = yield tester.http_client(tester.url_for('/hello'))
...
.. warning::
You can't use multiple Testers in one gen_test by default.
You should provide a shared I/O loop to use multiple tester. ::
import pytest
from tornado.ioloop import IOLoop
from tornado_tester import gen_test, Tester
from yourapplication import app
@gen_test
def test_app():
loop = IOLoop()
tester1 = Tester(app, io_loop=loop)
tester2 = Tester(app, io_loop=loop)
with tester1:
...
with tester2:
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Tornado-Tester-0.1.1.tar.gz
(1.4 kB
view details)
File details
Details for the file Tornado-Tester-0.1.1.tar.gz
.
File metadata
- Download URL: Tornado-Tester-0.1.1.tar.gz
- Upload date:
- Size: 1.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b692439af6d058d3ac4c954e99e88dcde93e37ed9973f14b7640a593898a3b43 |
|
MD5 | dfb976adec798f4cf8dbe40fbe5fd088 |
|
BLAKE2b-256 | ed6cf10c27e93cdcaa3b0ad72846fe091a470ccc7159fb82857c23b144483878 |