"""``async_test`` that closes the app's per-loop Tortoise context.""" from __future__ import annotations import asyncio from functools import wraps from typing import Any, Callable, Coroutine from kca.app import tortoise_mixin def async_test(coro: Callable[..., Coroutine[Any, Any, None]]) -> Callable[..., None]: @wraps(coro) def wrapper(*args: Any, **kwargs: Any) -> None: async def run() -> None: try: await coro(*args, **kwargs) finally: await tortoise_mixin.aclose() with asyncio.Runner() as runner: runner.run(run()) return wrapper