diff --git a/pyproject.toml b/pyproject.toml index 03b5d9a9..98eb2958 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ zookeeper = ["kazoo"] test = [ "APScheduler[mongodb,redis,rethinkdb,sqlalchemy,tornado,zookeeper,etcd]", "pytest", - "pytest-asyncio >= 0.24.0", + "anyio >= 4.5.2", "PySide6; python_implementation == 'CPython' and python_version < '3.14'", "gevent; python_version < '3.14'", "twisted; python_version < '3.14'", @@ -98,8 +98,6 @@ local_scheme = "dirty-tag" addopts = "-rsx --tb=short" testpaths = "tests" filterwarnings = "always" -asyncio_mode = "strict" -asyncio_default_fixture_loop_scope = "function" markers = [ "external_service: marks tests as requiring some external service", ] diff --git a/tests/conftest.py b/tests/conftest.py index 03da555e..903b689f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,11 @@ from apscheduler.schedulers.blocking import BlockingScheduler +@pytest.fixture +def anyio_backend(): + return "asyncio" + + @pytest.fixture def timezone(monkeypatch): tz = pytz.timezone("Europe/Berlin") diff --git a/tests/test_executors.py b/tests/test_executors.py index 7acc3932..a88c045f 100644 --- a/tests/test_executors.py +++ b/tests/test_executors.py @@ -51,15 +51,15 @@ def executor(request, mock_scheduler): @pytest.fixture -def asyncio_scheduler(event_loop): - scheduler = AsyncIOScheduler(event_loop=event_loop) +async def asyncio_scheduler(): + scheduler = AsyncIOScheduler() scheduler.start(paused=True) yield scheduler scheduler.shutdown(False) @pytest.fixture -def asyncio_executor(asyncio_scheduler): +async def asyncio_executor(asyncio_scheduler): executor = AsyncIOExecutor() executor.start(asyncio_scheduler, "default") yield executor @@ -207,7 +207,7 @@ def func(): assert len(foos) == 0 -@pytest.mark.asyncio +@pytest.mark.anyio async def test_run_async_job_memory_leak(): class FooBar: pass @@ -253,7 +253,7 @@ def listener(evt): @pytest.mark.parametrize("exception", [False, True]) -@pytest.mark.asyncio +@pytest.mark.anyio async def test_run_coroutine_job(asyncio_scheduler, asyncio_executor, exception): from asyncio import Future, sleep @@ -273,7 +273,7 @@ async def test_run_coroutine_job(asyncio_scheduler, asyncio_executor, exception) @pytest.mark.parametrize("exception", [False, True]) -@pytest.mark.asyncio +@pytest.mark.anyio async def test_run_coroutine_job_tornado( tornado_scheduler, tornado_executor, exception ): @@ -295,7 +295,7 @@ async def test_run_coroutine_job_tornado( assert events[0].retval is True -@pytest.mark.asyncio +@pytest.mark.anyio async def test_asyncio_executor_shutdown(asyncio_scheduler, asyncio_executor): """Test that the AsyncIO executor cancels its pending tasks on shutdown.""" from asyncio import sleep diff --git a/tests/test_schedulers.py b/tests/test_schedulers.py index 4bed2b4a..eb497df6 100644 --- a/tests/test_schedulers.py +++ b/tests/test_schedulers.py @@ -1,3 +1,4 @@ +import asyncio import logging import pickle from datetime import datetime, timedelta @@ -37,6 +38,7 @@ SchedulerAlreadyRunningError, SchedulerNotRunningError, ) +from apscheduler.schedulers.asyncio import AsyncIOScheduler from apscheduler.schedulers.base import STATE_RUNNING, STATE_STOPPED, BaseScheduler from apscheduler.triggers.base import BaseTrigger from apscheduler.util import undefined @@ -1148,20 +1150,22 @@ def scheduler(self): class TestAsyncIOScheduler(SchedulerImplementationTestBase): @pytest.fixture - def scheduler(self, event_loop): - asyncio = pytest.importorskip("apscheduler.schedulers.asyncio") - return asyncio.AsyncIOScheduler(event_loop=event_loop) + def scheduler(self): + return AsyncIOScheduler() @pytest.fixture - def start_scheduler(self, request, event_loop, scheduler): - event_loop.call_soon_threadsafe(scheduler.start) + def start_scheduler(self, request, scheduler): + event_loop = asyncio.new_event_loop() + event_loop.call_soon(scheduler.start) thread = Thread(target=event_loop.run_forever) yield thread.start if scheduler.running: event_loop.call_soon_threadsafe(scheduler.shutdown) + event_loop.call_soon_threadsafe(event_loop.stop) thread.join() + event_loop.close() class TestGeventScheduler(SchedulerImplementationTestBase):