Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Hypothesis plugin for trio

Project description

Welcome to hypothesis-trio!

Hypothesis supports Trio out of the box for non-stateful tests. This project aims at supporting the stateful mode ;-)

License: Your choice of MIT or Apache License 2.0


Replace hypothesis.stateful.RuleBasedStateMachine by hypothesis_trio.stateful.TrioRuleBasedStateMachine:

from hypothesis_trio.stateful import TrioRuleBasedStateMachine, run_state_machine_as_test

def test_trio_number_modifier(hypothesis_settings):
    class NumberModifier(TrioRuleBasedStateMachine):

        folders = Bundle('folders')
        files = Bundle('files')

        async def init_folders(self):
            await trio.sleep(0)
            return '/'

        @rule(target=folders, name=name_strategy)
        async def create_folder(self, parent, name):
            await trio.sleep(0)
            return '%s/%s' % (parent, name)

        @rule(target=files, name=name_strategy)
        async def create_file(self, parent, name):
            await trio.sleep(0)
            return '%s/%s' % (parent, name)

        async def teardown(self):
            await trio.sleep(0)

    run_state_machine_as_test(NumberModifier, settings=hypothesis_settings)

Support for Trio-Asyncio

trio-asyncio allows to mix asyncio and trio code altogether. To support it in your test, you should use hypothesis_trio.stateful.TrioAsyncioRuleBasedStateMachine:

class CheckAsyncioLoop(TrioAsyncioRuleBasedStateMachine):

    async def initialize(self):
        assert self.get_asyncio_loop() == asyncio.get_event_loop()
        await trio_asyncio.aio_as_trio(lambda: asyncio.sleep(0))

Project details

Download files

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

Files for hypothesis-trio, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size hypothesis_trio-0.4.0-py3-none-any.whl (13.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size hypothesis-trio-0.4.0.tar.gz (18.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page