Registry / testing / pytest-tornasync

pytest-tornasync

JSON →
library0.6.0.post2pypypi✓ verified 87d ago

pytest-tornasync is a simple pytest plugin that provides helpful fixtures for testing Tornado (version 5.0 or newer) applications. It simplifies testing native Python 3.5+ coroutines by eliminating the need for decorators like `@pytest.mark.gen_test`. The current version is 0.6.0.post2, with the last release in July 2019, indicating a stalled release cadence and an 'at risk' maintenance status, although the plugin remains functional for its intended purpose.

pip install pytest-tornasync
INSTALL
IMPORT
SIG · PYTEST-TORNASYNC
P
pytest-tornasync
testingpythonv0.6.0.post2
Install
3.0s avg
Import
421ms
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0.post2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.444s · 34.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.0s · import 0.398s · 35MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest.fixture
import pytest
pytest-tornasync itself provides fixtures that are automatically discovered by pytest; direct imports from pytest_tornasync are not typically needed for tests.
tornado.web.Application
import tornado.web
Used in the required 'app' fixture to define the Tornado application under test.

This quickstart demonstrates how to set up a basic Tornado application and test it using `pytest-tornasync`. The `app` fixture provides the `tornado.web.Application` instance, and the `http_server_client` fixture (provided by `pytest-tornasync`) is used to make asynchronous HTTP requests to the test server. Tests are defined as native Python `async def` functions.

import pytest import tornado.web from tornado.testing import AsyncHTTPTestCase # Define your Tornado application class MainHandler(tornado.web.RequestHandler): async def get(self): self.write("Hello, world") def make_app(): return tornado.web.Application([ (r"/", MainHandler), ]) # Define the 'app' fixture for pytest-tornasync @pytest.fixture def app(): return make_app() # Write an async test using the http_server_client fixture async def test_main_handler(http_server_client): response = await http_server_client.fetch('/') assert response.code == 200 assert response.body == b"Hello, world"
Debug
Known issues
breakingpytest-tornasync requires Tornado version 5.0 or newer and Python 3.5+. Older versions of Tornado or Python will not be supported and may lead to unexpected errors or incompatible behavior.
fix
Ensure your project uses Tornado 5.0+ and Python 3.5+ (or newer compatible versions). Review your `requirements.txt` or `pyproject.toml` to ensure correct version pinning.
affects: <=0.5.x
gotchaThe plugin automatically discovers fixtures. However, if the `app` fixture, which returns a `tornado.web.Application` instance, is not defined in your test suite, `pytest-tornasync` will raise a `FixtureLookupError: tornado application fixture not found` during test collection.
fix
Always define an `app` fixture in your `conftest.py` or test file, returning an instance of your `tornado.web.Application`. Example: `@pytest.fixture \ndef app(): \n    return your_app.make_app()`.
affects: All versions
gotchaUnlike `pytest-tornado`, `pytest-tornasync` is designed for plain native coroutine tests and does *not* require (or use) the `@pytest.mark.gen_test` decorator. Applying it might lead to unexpected behavior or redundant processing, as it is intended for a different async testing pattern.
fix
Remove `@pytest.mark.gen_test` from your async test functions when using `pytest-tornasync`. Simply define your tests as `async def test_something(...)`.
affects: All versions
gotchaAsync tests, especially those involving I/O or external services, can sometimes hang if the event loop is not correctly managed or if there are unhandled futures/tasks. This can manifest as `pytest` appearing to freeze indefinitely.
fix
Ensure all async operations are properly `await`ed or managed. Use `pytest --timeout=N` or `pytest-asyncio`'s timeout features if you suspect long-running or stuck coroutines. Check for resource deadlocks or unclosed connections.
affects: All versions
Errors
Common errors & fixes
FixtureLookupError: tornado application fixture not found
The `pytest-tornasync` plugin could not find a pytest fixture named `app` that is expected to provide the `tornado.web.Application` instance for testing.
fix
Create a fixture named `app` that returns your `tornado.web.Application`. Place this fixture in `conftest.py` or directly in your test file.
```python
import pytest
import tornado.web

@pytest.fixture
def app():
    # Your Tornado application setup
    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("Hello")
    return tornado.web.Application([(r"/", MainHandler)])
```
RuntimeError: No current event loop in thread 'Thread-X' (or similar errors related to asyncio event loop)
Your asynchronous Tornado test code is attempting to interact with the `asyncio` event loop (e.g., awaiting a future) outside of a running event loop context, or the event loop provided by `pytest-tornasync` is not being properly utilized.
fix
Ensure your async test functions are properly defined with `async def` and receive the necessary fixtures (e.g., `io_loop`, `http_server_client`) provided by `pytest-tornasync` to operate within its managed event loop. Avoid explicit `asyncio.get_event_loop()` calls unless you are managing the loop lifecycle manually.
TypeError: 'coroutine' object is not iterable (or similar errors when a test function is async but treated as sync)
Pytest is not recognizing your `async def` test function as an asynchronous test that needs to be run by an async-aware plugin. This often happens if `pytest-tornasync` is not correctly installed or enabled, or if another plugin is interfering.
fix
Verify that `pytest-tornasync` is correctly installed (`pip show pytest-tornasync`). Ensure no conflicting async plugins (like an older `pytest-tornado` that expects `@gen_test`) are enabled. Restart your pytest session to ensure plugin discovery.
Upgrade
Version history
0.6.0.post2latest on PyPI · released Jul 15, 2019
Audit
Dependencies
pytestrequiredCore testing framework, required for the plugin to function.
tornadorequiredAsynchronous web framework being tested; version 5.0 or newer is required.
Agent activity
15 hits · last 30 days
node
14
Resources