diff options
-rw-r--r-- | tests/test_datastores.py | 23 | ||||
-rw-r--r-- | tests/test_eventbrokers.py | 23 | ||||
-rw-r--r-- | tests/test_schedulers.py | 6 |
3 files changed, 28 insertions, 24 deletions
diff --git a/tests/test_datastores.py b/tests/test_datastores.py index 3edff4a..0b484f1 100644 --- a/tests/test_datastores.py +++ b/tests/test_datastores.py @@ -8,6 +8,7 @@ from typing import AsyncGenerator import anyio import pytest from freezegun.api import FrozenDateTimeFactory +from pytest_lazyfixture import lazy_fixture from apscheduler.abc import AsyncDataStore, DataStore, Job, Schedule from apscheduler.datastores.async_adapter import AsyncDataStoreAdapter @@ -89,13 +90,13 @@ async def asyncpg_store() -> AsyncDataStore: @pytest.fixture(params=[ - pytest.param(pytest.lazy_fixture('memory_store'), id='memory'), - pytest.param(pytest.lazy_fixture('sqlite'), id='sqlite'), - pytest.param(pytest.lazy_fixture('mongodb_store'), id='mongodb', + pytest.param(lazy_fixture('memory_store'), id='memory'), + pytest.param(lazy_fixture('sqlite'), id='sqlite'), + pytest.param(lazy_fixture('mongodb_store'), id='mongodb', marks=[pytest.mark.external_service]), - pytest.param(pytest.lazy_fixture('psycopg2_store'), id='psycopg2', + pytest.param(lazy_fixture('psycopg2_store'), id='psycopg2', marks=[pytest.mark.external_service]), - pytest.param(pytest.lazy_fixture('mysql_store'), id='mysql', + pytest.param(lazy_fixture('mysql_store'), id='mysql', marks=[pytest.mark.external_service]) ]) def sync_store(request) -> DataStore: @@ -103,7 +104,7 @@ def sync_store(request) -> DataStore: @pytest.fixture(params=[ - pytest.param(pytest.lazy_fixture('asyncpg_store'), id='asyncpg', + pytest.param(lazy_fixture('asyncpg_store'), id='asyncpg', marks=[pytest.mark.external_service]) ]) def async_store(request) -> AsyncDataStore: @@ -111,13 +112,13 @@ def async_store(request) -> AsyncDataStore: @pytest.fixture(params=[ - pytest.param(pytest.lazy_fixture('memory_store'), id='memory'), - pytest.param(pytest.lazy_fixture('sqlite_store'), id='sqlite'), - pytest.param(pytest.lazy_fixture('mongodb_store'), id='mongodb', + pytest.param(lazy_fixture('memory_store'), id='memory'), + pytest.param(lazy_fixture('sqlite_store'), id='sqlite'), + pytest.param(lazy_fixture('mongodb_store'), id='mongodb', marks=[pytest.mark.external_service]), - pytest.param(pytest.lazy_fixture('psycopg2_store'), id='psycopg2', + pytest.param(lazy_fixture('psycopg2_store'), id='psycopg2', marks=[pytest.mark.external_service]), - pytest.param(pytest.lazy_fixture('mysql_store'), id='mysql', + pytest.param(lazy_fixture('mysql_store'), id='mysql', marks=[pytest.mark.external_service]) ]) async def datastore(request): diff --git a/tests/test_eventbrokers.py b/tests/test_eventbrokers.py index efc9382..1d29ede 100644 --- a/tests/test_eventbrokers.py +++ b/tests/test_eventbrokers.py @@ -6,9 +6,10 @@ from queue import Empty, Queue from typing import Callable import pytest -from _pytest.fixtures import FixtureRequest +from _pytest.fixtures import SubRequest from _pytest.logging import LogCaptureFixture from anyio import create_memory_object_stream, fail_after +from pytest_lazyfixture import lazy_fixture from apscheduler.abc import AsyncEventBroker, EventBroker, Serializer from apscheduler.events import Event, ScheduleAdded @@ -60,28 +61,28 @@ async def asyncpg_broker(serializer: Serializer) -> AsyncEventBroker: @pytest.fixture(params=[ - pytest.param(pytest.lazy_fixture('local_broker'), id='local'), - pytest.param(pytest.lazy_fixture('redis_broker'), id='redis', + pytest.param(lazy_fixture('local_broker'), id='local'), + pytest.param(lazy_fixture('redis_broker'), id='redis', marks=[pytest.mark.external_service]), - pytest.param(pytest.lazy_fixture('mqtt_broker'), id='mqtt', + pytest.param(lazy_fixture('mqtt_broker'), id='mqtt', marks=[pytest.mark.external_service]) ]) -def broker(request: FixtureRequest) -> Callable[[], EventBroker]: +def broker(request: SubRequest) -> Callable[[], EventBroker]: return request.param @pytest.fixture(params=[ - pytest.param(pytest.lazy_fixture('local_async_broker'), id='local'), - pytest.param(pytest.lazy_fixture('asyncpg_broker'), id='asyncpg', + pytest.param(lazy_fixture('local_async_broker'), id='local'), + pytest.param(lazy_fixture('asyncpg_broker'), id='asyncpg', marks=[pytest.mark.external_service]) ]) -def async_broker(request: FixtureRequest) -> Callable[[], AsyncEventBroker]: +def async_broker(request: SubRequest) -> Callable[[], AsyncEventBroker]: return request.param class TestEventBroker: def test_publish_subscribe(self, broker: EventBroker) -> None: - queue = Queue() + queue: Queue[Event] = Queue() with broker: broker.subscribe(queue.put_nowait) broker.subscribe(queue.put_nowait) @@ -99,7 +100,7 @@ class TestEventBroker: assert event1.next_fire_time == datetime(2021, 9, 11, 12, 31, 56, 254867, timezone.utc) def test_subscribe_one_shot(self, broker: EventBroker) -> None: - queue = Queue() + queue: Queue[Event] = Queue() with broker: broker.subscribe(queue.put_nowait, one_shot=True) event = ScheduleAdded( @@ -118,7 +119,7 @@ class TestEventBroker: assert received_event.schedule_id == 'schedule1' def test_unsubscribe(self, broker: EventBroker, caplog) -> None: - queue = Queue() + queue: Queue[Event] = Queue() with broker: subscription = broker.subscribe(queue.put_nowait) broker.publish(Event()) diff --git a/tests/test_schedulers.py b/tests/test_schedulers.py index 7657cec..4a1cc4e 100644 --- a/tests/test_schedulers.py +++ b/tests/test_schedulers.py @@ -102,6 +102,8 @@ class TestAsyncScheduler: ]) async def test_jitter(self, mocker: MockerFixture, timezone: ZoneInfo, max_jitter: float, expected_upper_bound: float) -> None: + job_id: UUID | None = None + def job_added_listener(event: Event) -> None: nonlocal job_id assert isinstance(event, JobAdded) @@ -115,7 +117,6 @@ class TestAsyncScheduler: async with AsyncScheduler(start_worker=False) as scheduler: trigger = IntervalTrigger(seconds=3, start_time=orig_start_time) job_added_event = anyio.Event() - job_id: UUID | None = None scheduler.events.subscribe(job_added_listener, {JobAdded}) schedule_id = await scheduler.add_schedule(dummy_async_job, trigger, max_jitter=max_jitter) @@ -248,6 +249,8 @@ class TestSyncScheduler: ]) def test_jitter(self, mocker: MockerFixture, timezone: ZoneInfo, max_jitter: float, expected_upper_bound: float) -> None: + job_id: UUID | None = None + def job_added_listener(event: Event) -> None: nonlocal job_id assert isinstance(event, JobAdded) @@ -261,7 +264,6 @@ class TestSyncScheduler: with Scheduler(start_worker=False) as scheduler: trigger = IntervalTrigger(seconds=3, start_time=orig_start_time) job_added_event = threading.Event() - job_id: UUID | None = None scheduler.events.subscribe(job_added_listener, {JobAdded}) schedule_id = scheduler.add_schedule(dummy_async_job, trigger, max_jitter=max_jitter) schedule = scheduler.get_schedule(schedule_id) |