pytest-tornasync


Namepytest-tornasync JSON
Version 0.6.0.post2 PyPI version JSON
download
home_pagehttps://github.com/eukaryote/pytest-tornasync
Summarypy.test plugin for testing Python 3.5+ Tornado code
upload_time2019-07-15 08:41:13
maintainer
docs_urlNone
authorCalvin Smith
requires_python
licensehttp://www.opensource.org/licenses/mit-license.php
keywords testing py.test tornado
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ================
pytest-tornasync
================

.. image:: https://travis-ci.org/eukaryote/pytest-tornasync.svg?branch=master
    :target: https://travis-ci.org/eukaryote/pytest-tornasync

A simple pytest plugin that provides some helpful fixtures for testing
Tornado (version 5.0 or newer)  apps and easy handling of plain
(undecoratored) native coroutine tests (Python 3.5+).

Why another Tornado pytest plugin when the excellent ``pytest-tornado`` already
exists? The main reason is that I didn't want to have to decorate every test
coroutine with ``@pytest.mark.gen_test``. This plugin doesn't have anything
like ``gen_test``. Defining a test with ``async def`` and a name that
begins with ``test_`` is all that is required.


Installation
------------

Install using pip, which must be run with Python 3.5+:

.. code-block:: sh

    pip install pytest-tornasync


Usage
-----

Define an ``app`` fixture:

.. code-block:: python

    import pytest


    @pytest.fixture
    def app():
        import yourapp
        return yourapp.make_app()  # a tornado.web.Application


Create tests as native coroutines using Python 3.5+ ``async def``:

.. code-block:: python

    async def test_app(http_server_client):
        resp = await http_server_client.fetch('/')
        assert resp.code == 200
        # ...


Fixtures
--------

When the plugin is installed, then ``pytest --fixtures`` will show
the fixtures that are available:

http_server_port
    Port used by `http_server`.
http_server
    Start a tornado HTTP server that listens on all available interfaces.

    You must create an `app` fixture, which returns
    the `tornado.web.Application` to be tested.

    Raises:
    FixtureLookupError: tornado application fixture not found
http_server_client
    Create an asynchronous HTTP client that can fetch from `http_server`.
http_client
    Create an asynchronous HTTP client that can fetch from anywhere.
io_loop
    Create a new `tornado.ioloop.IOLoop` for each test case.



Examples
--------

.. code-block:: python

    import time

    import tornado.web
    import tornado.gen

    import pytest


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


    @pytest.fixture
    def app():
        return tornado.web.Application([(r"/", MainHandler)])


    async def test_http_server_client(http_server_client):
        # http_server_client fetches from the `app` fixture and takes path
        resp = await http_server_client.fetch('/')
        assert resp.code == 200
        assert resp.body == b"Hello, world!"


    async def test_http_client(http_client):
        # http_client fetches from anywhere and takes full URL
        resp = await http_client.fetch('http://httpbin.org/status/204')
        assert resp.code == 204


    async def example_coroutine(period):
        await tornado.gen.sleep(period)


    async def test_example():
        # no fixtures needed
        period = 1.0
        start = time.time()
        await example_coroutine(period)
        elapsed = time.time() - start
        assert elapsed >= period


Changes
=======

0.6.0 (2018-11-19)
------------------

 - minor updates to avoid a pytest warning under pytest 4
 - repo switch to using a 'src' dir


0.5.0 (2018-05-28)
------------------

 - updated to work with Tornado 5, which is now the minimum required version
 - require pytest >= 3.0
 - the `io_loop` fixture always refers to a `tornado.ioloop.IOLoop instance` now
 - the `io_loop_asyncio` and `io_loop_tornado` fixtures have been removed, since
   now that Tornado 5 always uses asyncio under Python 3, there would be no
   difference between the two fixtures, so `io_loop` is all that is needed
 - tox tests now test more versions of Tornado (5.0.* and latest 5.*),
   Pytest (3.0.* and latest 3.*), and Python (3.5, 3.6, 3.7, and pypy3).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eukaryote/pytest-tornasync",
    "name": "pytest-tornasync",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "testing py.test tornado",
    "author": "Calvin Smith",
    "author_email": "sapientdust+pytest-tornasync@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/54/a0/e096d3609793ea1c3bbf255f923da453b83728cfc9f10bcbab98d6932d74/pytest-tornasync-0.6.0.post2.tar.gz",
    "platform": "any",
    "description": "================\npytest-tornasync\n================\n\n.. image:: https://travis-ci.org/eukaryote/pytest-tornasync.svg?branch=master\n    :target: https://travis-ci.org/eukaryote/pytest-tornasync\n\nA simple pytest plugin that provides some helpful fixtures for testing\nTornado (version 5.0 or newer)  apps and easy handling of plain\n(undecoratored) native coroutine tests (Python 3.5+).\n\nWhy another Tornado pytest plugin when the excellent ``pytest-tornado`` already\nexists? The main reason is that I didn't want to have to decorate every test\ncoroutine with ``@pytest.mark.gen_test``. This plugin doesn't have anything\nlike ``gen_test``. Defining a test with ``async def`` and a name that\nbegins with ``test_`` is all that is required.\n\n\nInstallation\n------------\n\nInstall using pip, which must be run with Python 3.5+:\n\n.. code-block:: sh\n\n    pip install pytest-tornasync\n\n\nUsage\n-----\n\nDefine an ``app`` fixture:\n\n.. code-block:: python\n\n    import pytest\n\n\n    @pytest.fixture\n    def app():\n        import yourapp\n        return yourapp.make_app()  # a tornado.web.Application\n\n\nCreate tests as native coroutines using Python 3.5+ ``async def``:\n\n.. code-block:: python\n\n    async def test_app(http_server_client):\n        resp = await http_server_client.fetch('/')\n        assert resp.code == 200\n        # ...\n\n\nFixtures\n--------\n\nWhen the plugin is installed, then ``pytest --fixtures`` will show\nthe fixtures that are available:\n\nhttp_server_port\n    Port used by `http_server`.\nhttp_server\n    Start a tornado HTTP server that listens on all available interfaces.\n\n    You must create an `app` fixture, which returns\n    the `tornado.web.Application` to be tested.\n\n    Raises:\n    FixtureLookupError: tornado application fixture not found\nhttp_server_client\n    Create an asynchronous HTTP client that can fetch from `http_server`.\nhttp_client\n    Create an asynchronous HTTP client that can fetch from anywhere.\nio_loop\n    Create a new `tornado.ioloop.IOLoop` for each test case.\n\n\n\nExamples\n--------\n\n.. code-block:: python\n\n    import time\n\n    import tornado.web\n    import tornado.gen\n\n    import pytest\n\n\n    class MainHandler(tornado.web.RequestHandler):\n        def get(self):\n            self.write(\"Hello, world!\")\n\n\n    @pytest.fixture\n    def app():\n        return tornado.web.Application([(r\"/\", MainHandler)])\n\n\n    async def test_http_server_client(http_server_client):\n        # http_server_client fetches from the `app` fixture and takes path\n        resp = await http_server_client.fetch('/')\n        assert resp.code == 200\n        assert resp.body == b\"Hello, world!\"\n\n\n    async def test_http_client(http_client):\n        # http_client fetches from anywhere and takes full URL\n        resp = await http_client.fetch('http://httpbin.org/status/204')\n        assert resp.code == 204\n\n\n    async def example_coroutine(period):\n        await tornado.gen.sleep(period)\n\n\n    async def test_example():\n        # no fixtures needed\n        period = 1.0\n        start = time.time()\n        await example_coroutine(period)\n        elapsed = time.time() - start\n        assert elapsed >= period\n\n\nChanges\n=======\n\n0.6.0 (2018-11-19)\n------------------\n\n - minor updates to avoid a pytest warning under pytest 4\n - repo switch to using a 'src' dir\n\n\n0.5.0 (2018-05-28)\n------------------\n\n - updated to work with Tornado 5, which is now the minimum required version\n - require pytest >= 3.0\n - the `io_loop` fixture always refers to a `tornado.ioloop.IOLoop instance` now\n - the `io_loop_asyncio` and `io_loop_tornado` fixtures have been removed, since\n   now that Tornado 5 always uses asyncio under Python 3, there would be no\n   difference between the two fixtures, so `io_loop` is all that is needed\n - tox tests now test more versions of Tornado (5.0.* and latest 5.*),\n   Pytest (3.0.* and latest 3.*), and Python (3.5, 3.6, 3.7, and pypy3).\n\n\n",
    "bugtrack_url": null,
    "license": "http://www.opensource.org/licenses/mit-license.php",
    "summary": "py.test plugin for testing Python 3.5+ Tornado code",
    "version": "0.6.0.post2",
    "split_keywords": [
        "testing",
        "py.test",
        "tornado"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50b93615ebfc3120bb949c3725b50793f42c3230d0175d6cfd358ea8bb6928ff",
                "md5": "c9fa07eb02c044f5a1c943d9e723fc61",
                "sha256": "4b165b6ba76b5b228933598f456b71ba233f127991a52889788db0a950ad04ba"
            },
            "downloads": -1,
            "filename": "pytest_tornasync-0.6.0.post2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c9fa07eb02c044f5a1c943d9e723fc61",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6634,
            "upload_time": "2019-07-15T08:41:12",
            "upload_time_iso_8601": "2019-07-15T08:41:12.234490Z",
            "url": "https://files.pythonhosted.org/packages/50/b9/3615ebfc3120bb949c3725b50793f42c3230d0175d6cfd358ea8bb6928ff/pytest_tornasync-0.6.0.post2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54a0e096d3609793ea1c3bbf255f923da453b83728cfc9f10bcbab98d6932d74",
                "md5": "c81f6f5975666e9bfaaa31a349ae3e17",
                "sha256": "d781b6d951a2e7c08843141d3ff583610b4ea86bfa847714c76edefb576bbe5d"
            },
            "downloads": -1,
            "filename": "pytest-tornasync-0.6.0.post2.tar.gz",
            "has_sig": false,
            "md5_digest": "c81f6f5975666e9bfaaa31a349ae3e17",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6201,
            "upload_time": "2019-07-15T08:41:13",
            "upload_time_iso_8601": "2019-07-15T08:41:13.921038Z",
            "url": "https://files.pythonhosted.org/packages/54/a0/e096d3609793ea1c3bbf255f923da453b83728cfc9f10bcbab98d6932d74/pytest-tornasync-0.6.0.post2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-07-15 08:41:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "eukaryote",
    "github_project": "pytest-tornasync",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "pytest-tornasync"
}
        
Elapsed time: 0.03211s