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 creating and injecting versions of the curio kernel

  • fixtures for injecting unused tcp ports

  • 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-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_curio-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest-curio-0.1.0.tar.gz.

File metadata

  • Download URL: pytest-curio-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytest-curio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a5969ac515ac3e41de4399bd4b6f9f00c815500eef5f90e96432ce456dcd513d
MD5 293ef3c5fa2042fa210299a11f7c40a7
BLAKE2b-256 66a1ef64ed8bf855a825573b0b69f30bb52f69f8f37258996742cb158bcf4c5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_curio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3b870501ca55d61e9e1f8972669dc5f341fd25f559dd10a6a7239da7b73fca0
MD5 4ca1e003f0a5d70df73358e670fc4f8f
BLAKE2b-256 3a14cc4664ae47ea6523d06854ee46c02bf7735dd4c9784812e3bdc0d8044bcb

See more details on using hashes here.

Supported by

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