From c80a51e2e1b959d597c6dfcc162c64d4648086e9 Mon Sep 17 00:00:00 2001 From: wrmsr Date: Tue, 7 Jan 2025 13:47:38 -0500 Subject: [PATCH] 2025-01-07T18:47:38Z --- .../pytest/plugins/asyncs/backends/base.py | 2 +- .../plugins/asyncs/backends/trio_asyncio.py | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/omlish/testing/pytest/plugins/asyncs/backends/base.py b/omlish/testing/pytest/plugins/asyncs/backends/base.py index 4ab63e2a8..ca94b8ed1 100644 --- a/omlish/testing/pytest/plugins/asyncs/backends/base.py +++ b/omlish/testing/pytest/plugins/asyncs/backends/base.py @@ -6,5 +6,5 @@ class AsyncsBackend(abc.ABC): def wrap_runner(self, fn): raise NotImplementedError - async def install_context(self, contextvars_ctx): + async def install_context(self, contextvars_ctx): # noqa pass diff --git a/omlish/testing/pytest/plugins/asyncs/backends/trio_asyncio.py b/omlish/testing/pytest/plugins/asyncs/backends/trio_asyncio.py index 3e64d555b..e97fa8d47 100644 --- a/omlish/testing/pytest/plugins/asyncs/backends/trio_asyncio.py +++ b/omlish/testing/pytest/plugins/asyncs/backends/trio_asyncio.py @@ -23,12 +23,10 @@ from _pytest.outcomes import XFailed # noqa from ...... import lang -from ..fixtures import CANARY from .base import AsyncsBackend if ta.TYPE_CHECKING: - import trio import trio_asyncio else: trio = lang.proxy_import('trio', extras=['abc']) @@ -43,20 +41,25 @@ def wrap_runner(self, fn): @functools.wraps(fn) def wrapper(**kwargs): return trio_asyncio.run( - functools.partial(fn, **kwargs), + trio_asyncio.aio_as_trio( + functools.partial(fn, **kwargs), + ), ) return wrapper async def install_context(self, contextvars_ctx): + # Seemingly no longer necessary? # https://github.com/python-trio/pytest-trio/commit/ef0cd267ea62188a8e475c66cb584e7a2addc02a - # This is a gross hack. I guess Trio should provide a context= argument to start_soon/start? - task = trio.lowlevel.current_task() - if CANARY in task.context: - return + # # This is a gross hack. I guess Trio should provide a context= argument to start_soon/start? + # task = trio.lowlevel.current_task() + # if CANARY in task.context: + # return - task.context = contextvars_ctx + # task.context = contextvars_ctx - # Force a yield so we pick up the new context - await trio.sleep(0) + # # Force a yield so we pick up the new context + # await trio.sleep(0) + + pass