Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make start_soon always start soon - support eager tasks #851

Closed
wants to merge 12 commits into from
43 changes: 14 additions & 29 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,27 @@

pytest_plugins = ["pytester", "pytest_mock"]

if sys.version_info < (3, 13):
if sys.platform == "win32":
EventLoop = asyncio.ProactorEventLoop
else:
EventLoop = asyncio.SelectorEventLoop
else:
EventLoop = asyncio.EventLoop

if sys.version_info >= (3, 12):

def eager_task_loop_factory() -> EventLoop:
loop = EventLoop()
loop.set_task_factory(asyncio.eager_task_factory)
return loop

eager_marks: list[pytest.MarkDecorator] = []
else:
eager_task_loop_factory = EventLoop
eager_marks = [pytest.mark.skip(reason="eager tasks not supported yet")]

asyncio_params = [
pytest.param(
("asyncio", {"debug": True, "loop_factory": None}),
id="asyncio",
),
pytest.param(("asyncio", {"debug": True}), id="asyncio"),
pytest.param(
("asyncio", {"debug": True, "loop_factory": uvloop.new_event_loop}),
marks=uvloop_marks,
id="asyncio+uvloop",
),
pytest.param(
("asyncio", {"debug": True, "loop_factory": eager_task_loop_factory}),
marks=eager_marks,
id="asyncio+eager",
),
]
if sys.version_info >= (3, 12):

def eager_task_loop_factory() -> asyncio.AbstractEventLoop:
loop = asyncio.new_event_loop()
graingert marked this conversation as resolved.
Show resolved Hide resolved
loop.set_task_factory(asyncio.eager_task_factory)
return loop

asyncio_params.append(
pytest.param(
("asyncio", {"debug": True, "loop_factory": eager_task_loop_factory}),
id="asyncio+eager",
),
)


@pytest.fixture(params=[*asyncio_params, pytest.param("trio")])
Expand Down
8 changes: 4 additions & 4 deletions tests/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from anyio.abc import TaskGroup, TaskStatus
from anyio.lowlevel import checkpoint

from .conftest import EventLoop, asyncio_params
from .conftest import asyncio_params

if sys.version_info < (3, 11):
from exceptiongroup import BaseExceptionGroup, ExceptionGroup
Expand Down Expand Up @@ -1782,9 +1782,9 @@ async def sync_coro() -> None:

def task_factory_loop_factory_factory(
task_factory: Callable[..., Any],
) -> Callable[[], EventLoop]:
def factory() -> EventLoop:
loop = EventLoop()
) -> Callable[[], asyncio.AbstractEventLoop]:
def factory() -> asyncio.AbstractEventLoop:
loop = asyncio.new_event_loop()
loop.set_task_factory(task_factory)
return loop

Expand Down
Loading