Esempio n. 1
0
    def _custom_runner(self, data, print_steps, should_continue):
        async def _run(**kwargs):
            async with trio.open_nursery() as self._nursery:
                try:
                    if print_steps:
                        self.print_start()
                    await self.check_invariants()

                    while should_continue.more():
                        value = data.draw(self.steps())
                        if print_steps:
                            self.print_step(value)
                        await self.execute_step(value)
                        await self.check_invariants()
                finally:
                    if print_steps:
                        self.print_end()
                    await self.teardown()
                    self._nursery.cancel_scope.cancel()

        self.__started = True
        kwargs = {
            'instrument_%s' % i: instrument
            for i, instrument in enumerate(self.__instruments)
        }
        if self.__clock:
            kwargs['clock'] = self.__clock
        trio_test(_run)(**kwargs)
Esempio n. 2
0
 def trio_run(self, corofn, *args):
     self.__started = True
     kwargs = {
         'instrument_%s' % i: instrument
         for i, instrument in enumerate(self.__instruments)
     }
     if self.__clock:
         kwargs['clock'] = self.__clock
     trio_test(self._trio_main_afn_factory(corofn, *args))(**kwargs)
Esempio n. 3
0
    def trio_run(self, corofn, *args):
        async def _run(**kwargs):
            async with trio.open_nursery() as self._nursery:
                await corofn(*args)
                self._nursery.cancel_scope.cancel()

        self.__started = True
        kwargs = {
            'instrument_%s' % i: instrument
            for i, instrument in enumerate(self.__instruments)
        }
        if self.__clock:
            kwargs['clock'] = self.__clock
        trio_test(_run)(**kwargs)
Esempio n. 4
0
def pytest_pyfunc_call(pyfuncitem):
    if inspect.iscoroutinefunction(pyfuncitem.obj):
        pyfuncitem.obj = trio_test(pyfuncitem.obj)