Skip to content

Commit

Permalink
Fixed test failures on Windows and remove the sqlite store fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Dec 3, 2023
1 parent 8ad9270 commit b64ba91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
30 changes: 7 additions & 23 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/test_schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b64ba91

Please sign in to comment.