From b64ba918f52c676f1603b7b556a844c978ad67a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Mon, 4 Dec 2023 00:42:30 +0200 Subject: [PATCH] Fixed test failures on Windows and remove the sqlite store fixture --- tests/conftest.py | 30 +++++++----------------------- tests/test_schedulers.py | 3 +-- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f22f9fd9b..7f6a57b50 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,7 @@ from collections.abc import Generator from contextlib import AsyncExitStack from logging import Logger -from tempfile import TemporaryDirectory +from pathlib import Path from typing import Any, AsyncGenerator, cast import pytest @@ -132,21 +132,6 @@ def mongodb_store() -> Generator[DataStore, None, None]: yield MongoDBDataStore(client, start_from_scratch=True) -@pytest.fixture -def sqlite_store() -> Generator[DataStore, None, None]: - from sqlalchemy import create_engine - - from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore - - with TemporaryDirectory("sqlite_") as tempdir: - engine = create_engine(f"sqlite:///{tempdir}/test.db") - try: - yield SQLAlchemyDataStore(engine) - assert "Current Checked out connections: 0" in engine.pool.status() - finally: - engine.dispose() - - @pytest.fixture async def psycopg_async_store() -> AsyncGenerator[DataStore, None]: from sqlalchemy import text @@ -203,17 +188,16 @@ def pymysql_store() -> Generator[DataStore, None, None]: @pytest.fixture -async def aiosqlite_store() -> AsyncGenerator[DataStore, None]: +async def aiosqlite_store(tmp_path: Path) -> AsyncGenerator[DataStore, None]: from sqlalchemy.ext.asyncio import create_async_engine from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore - with TemporaryDirectory("sqlite_") as tempdir: - engine = create_async_engine(f"sqlite+aiosqlite:///{tempdir}/test.db") - try: - yield SQLAlchemyDataStore(engine) - finally: - await engine.dispose() + engine = create_async_engine(f"sqlite+aiosqlite:///{tmp_path}/test.db") + try: + yield SQLAlchemyDataStore(engine) + finally: + await engine.dispose() @pytest.fixture diff --git a/tests/test_schedulers.py b/tests/test_schedulers.py index c72a0e6eb..228d9141b 100644 --- a/tests/test_schedulers.py +++ b/tests/test_schedulers.py @@ -396,8 +396,7 @@ async def test_scheduled_job_missed_deadline( self, raw_datastore: DataStore, timezone: ZoneInfo ) -> None: send, receive = create_memory_object_stream[Event](4) - now = datetime.now(timezone) - trigger = DateTrigger(now) + trigger = DateTrigger(datetime.now(timezone) - timedelta(seconds=1)) async with AsyncScheduler(data_store=raw_datastore) as scheduler: await scheduler.add_schedule( dummy_async_job, trigger, misfire_grace_time=0, id="foo"