From b3c6bca584db5658dfcae8ad02ab39aa07fb9cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Thu, 22 Sep 2022 01:00:16 +0300 Subject: Fixed the test suite on PyPy --- .github/workflows/test.yml | 2 +- pyproject.toml | 18 ++++++++++++------ tests/conftest.py | 11 ++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 94b8031..4e05b1f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.10", "3.11-dev"] + python-version: ["3.7", "3.10", "3.11-dev", "pypy-3.9"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/pyproject.toml b/pyproject.toml index a45f573..ef794e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,16 +41,19 @@ cbor = ["cbor2 >= 5.0"] mongodb = ["pymongo >= 4"] mqtt = ["paho-mqtt >= 1.5"] redis = ["redis >= 4.0"] -sqlalchemy = ["sqlalchemy >= 1.4.22"] +sqlalchemy = [ + "sqlalchemy >= 1.4.22", + "greenlet >= 2.0.0a2; python_version >= '3.11'" +] test = [ - "asyncpg >= 0.20", - "asyncmy >= 0.2.5", - "cbor2 >= 5.0", + "APScheduler[cbor,mongodb,mqtt,redis,sqlalchemy]", + "APScheduler[asyncpg]; python_implementation == 'CPython'", + "asyncmy >= 0.2.5; python_implementation == 'CPython'", "coverage", "freezegun", - "greenlet >= 2.0.0a2; python_version >= '3.11'", "paho-mqtt >= 1.5", - "psycopg2", + "psycopg2; python_implementation == 'CPython'", + "psycopg2cffi; python_implementation != 'CPython'", "pymongo >= 4", "pymysql[rsa]", "pytest >= 5.0", @@ -110,6 +113,9 @@ isolated_build = true extras = test commands = coverage run -m pytest {posargs} +[testenv:pypy3] +commands = pytest {posargs} + [testenv:pyright] deps = pyright commands = pyright --verifytypes apscheduler diff --git a/tests/conftest.py b/tests/conftest.py index 0de4349..92e9d92 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ from __future__ import annotations +import platform import sys from contextlib import AsyncExitStack from tempfile import TemporaryDirectory @@ -71,6 +72,7 @@ def mqtt_broker(serializer: Serializer) -> EventBroker: @pytest.fixture async def asyncpg_broker(serializer: Serializer) -> EventBroker: + pytest.importorskip("asyncpg", reason="asyncpg is not installed") from apscheduler.eventbrokers.asyncpg import AsyncpgEventBroker broker = AsyncpgEventBroker.from_dsn( @@ -146,7 +148,12 @@ def psycopg2_store() -> DataStore: from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore - engine = create_engine("postgresql+psycopg2://postgres:secret@localhost/testdb") + if platform.python_implementation() == "CPython": + dialect = "psycopg2" + else: + dialect = "psycopg2cffi" + + engine = create_engine(f"postgresql+{dialect}://postgres:secret@localhost/testdb") try: with engine.begin() as conn: conn.execute(text("CREATE SCHEMA IF NOT EXISTS psycopg2")) @@ -171,6 +178,7 @@ def pymysql_store() -> DataStore: @pytest.fixture async def asyncpg_store() -> DataStore: + pytest.importorskip("asyncpg", reason="asyncpg is not installed") from sqlalchemy.ext.asyncio import create_async_engine from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore @@ -186,6 +194,7 @@ async def asyncpg_store() -> DataStore: @pytest.fixture async def asyncmy_store() -> DataStore: + pytest.importorskip("asyncmy", reason="asyncmy is not installed") from sqlalchemy.ext.asyncio import create_async_engine from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore -- cgit v1.2.1