From 3a8977cbc34e87ebdeda9253beb9d16ff80ee3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Mon, 27 Nov 2023 00:15:04 +0200 Subject: [PATCH] Skip tests requiring time-machine on implementation other than CPython PyPy and time machine are not compatible at the moment. --- pyproject.toml | 2 +- tests/test_datastores.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0b6df011..40d31ea4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ test = [ "pytest >= 7.4.0", "pytest-lazy-fixture", "pytest-mock", - "time-machine >= 2.13.0", + "time-machine >= 2.13.0; python_implementation == 'CPython'", "uwsgi; python_implementation == 'CPython' and platform_system == 'Linux'", ] doc = [ diff --git a/tests/test_datastores.py b/tests/test_datastores.py index cc634e46..55e57a93 100644 --- a/tests/test_datastores.py +++ b/tests/test_datastores.py @@ -1,14 +1,14 @@ from __future__ import annotations +import platform from contextlib import AsyncExitStack, asynccontextmanager from datetime import datetime, timedelta, timezone from logging import Logger -from typing import AsyncGenerator +from typing import TYPE_CHECKING, AsyncGenerator import anyio import pytest from anyio import CancelScope -from time_machine import TimeMachineFixture from apscheduler import ( CoalescePolicy, @@ -29,6 +29,9 @@ from apscheduler.abc import DataStore, EventBroker from apscheduler.triggers.date import DateTrigger +if TYPE_CHECKING: + from time_machine import TimeMachineFixture + pytestmark = pytest.mark.anyio @@ -177,6 +180,10 @@ async def test_remove_schedules( assert not events +@pytest.mark.skipif( + platform.python_implementation() != "CPython", + reason="time-machine is not available", +) async def test_acquire_release_schedules( datastore: DataStore, schedules: list[Schedule], time_machine: TimeMachineFixture ) -> None: @@ -269,6 +276,10 @@ async def test_release_two_schedules_at_once(datastore: DataStore) -> None: assert len(remaining) == 2 +@pytest.mark.skipif( + platform.python_implementation() != "CPython", + reason="time-machine is not available", +) async def test_acquire_schedules_lock_timeout( datastore: DataStore, schedules: list[Schedule], @@ -439,6 +450,10 @@ async def test_job_release_cancelled(datastore: DataStore) -> None: assert not await datastore.get_job_result(acquired[0].id) +@pytest.mark.skipif( + platform.python_implementation() != "CPython", + reason="time-machine is not available", +) async def test_acquire_jobs_lock_timeout( datastore: DataStore, time_machine: TimeMachineFixture ) -> None: