Skip to main content

Pytest support for curio.

Project description

curio code is written in the form of async/await, which makes it slightly more difficult to test using normal testing tools. pytest-curio provides useful fixtures and markers to make testing easier.

@pytest.mark.curio
async def test_some_curio_code():
    res = await library.do_something()
    assert b'expected result' == res

pytest-curio has been strongly influenced by pytest-asyncio.

Features

  • fixtures for injecting curio kernel

  • pytest markers for treating tests as curio coroutines

Installation

To install pytest-curio, simply:

$ pip install pytest-curio

This is enough for pytest to pick up pytest-curio.

Fixtures

kernel

Creates and injects a new instance of the default curio kernel. The kernel will be stoped at the end of the test.

Note that just using the kernel fixture won’t make your test function a coroutine. You’ll need to interact with the kernel directly, using methods like kernel.run. See the pytest.mark.curio marker for treating test functions like coroutines.

def test_http_client(kernel):
    result = []
    async def my_coroutine(obj):
        result.append(obj)
    url = 'http://httpbin.org/get'
    task = kernel.run(my_coroutine(url))
    assert url in result

Markers

pytest.mark.curio

Mark your test coroutine with this marker and pytest will execute it as an curio task using the kernel provided by the kernel fixture. See the introductory section for an example.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_curio-1.1.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

pytest_curio-1.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_curio-1.1.0.tar.gz.

File metadata

  • Download URL: pytest_curio-1.1.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for pytest_curio-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3dcc9ef052f7efc65d29edd4b2fc1033087ef264047a7332faa7022dce4dbc6d
MD5 4285e0361bdc95715f45532058c62633
BLAKE2b-256 70e903b12b551e72720db4e0f619db618212ca0c35e6c5c2f1c09354f06d0322

See more details on using hashes here.

File details

Details for the file pytest_curio-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_curio-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for pytest_curio-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2ce874c22491c327efcc33800c6f9abd6e5479aa6e9b824852b08783004b2a6
MD5 a2c88cd9945dffbb0c70d90c6acb5f3f
BLAKE2b-256 8c024a29dd2b902ae667da6b9d123d7f54a2b344d229b94666a0f80c7d787b9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page