Skip to content

Commit

Permalink
2025-01-07T18:47:38Z
Browse files Browse the repository at this point in the history
  • Loading branch information
wrmsr committed Jan 7, 2025
1 parent 71c6548 commit c80a51e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion omlish/testing/pytest/plugins/asyncs/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 13 additions & 10 deletions omlish/testing/pytest/plugins/asyncs/backends/trio_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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

0 comments on commit c80a51e

Please sign in to comment.