diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 706b7ac41a..f68f5b7fd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,16 +63,12 @@ jobs: - name: Install dependencies run: | - if [[ ${{ matrix.db }} == "postgres" ]]; then - DB="-E postgres" - else - DB="-E postgres-psycopg-binary" - fi - poetry install --with dev --without docs --no-interaction -E gunicorn $DB + poetry install --with dev --without docs --no-interaction -E gunicorn -E postgres-psycopg-binary - name: Test with pytest env: COVERAGE_FILE: coverage-data-v1-${{ matrix.python-version }}-${{ matrix.db }} + DB_ENGINE: ${{ matrix.db }} run: poetry run coverage run --concurrency=thread,greenlet,multiprocessing -m pytest --ignore tests/no_version --ignore tests/v2 - name: Upload coverage data @@ -143,16 +139,12 @@ jobs: - name: Install dependencies run: | - if [[ ${{ matrix.db }} == "postgres" ]]; then - DB="-E postgres" - elif [[ ${{ matrix.db }} == "postgres-psycopg" ]]; then - DB="-E postgres-psycopg-binary" - fi - poetry install --with dev --without docs --no-interaction -E gunicorn $DB + poetry install --with dev --without docs --no-interaction -E gunicorn -E postgres-psycopg-binary - name: Test with pytest env: COVERAGE_FILE: coverage-data-v2-${{ matrix.python-version }}-${{ matrix.db }} + DB_ENGINE: ${{ matrix.db }} run: poetry run coverage run --concurrency=thread,greenlet,multiprocessing -m pytest tests/v2 tests/no_version --ignore tests/v1 - name: Upload coverage data diff --git a/CHANGELOG.md b/CHANGELOG.md index 7346029747..afdc8e9c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ * Testing: * Benchmark `GET /api/v2/task-group/` (\#1922). * Use new `ubuntu22-slurm-multipy` image, with Python3.12 and with Python-version specific venvs (\#1946, #1969). + * Get `DB_ENGINE` variable from `os.environ` rather than from installed packages (\#1968). # 2.6.4 diff --git a/tests/fixtures_server.py b/tests/fixtures_server.py index fbe279737d..d30db8d08e 100644 --- a/tests/fixtures_server.py +++ b/tests/fixtures_server.py @@ -1,4 +1,5 @@ import logging +import os import random import sys from dataclasses import dataclass @@ -27,12 +28,7 @@ from fractal_server.config import Settings from fractal_server.syringe import Inject -try: - import psycopg # noqa: F401 - - DB_ENGINE = "postgres-psycopg" -except ModuleNotFoundError: - DB_ENGINE = "sqlite" +DB_ENGINE = os.environ.get("DB_ENGINE", "postgres-psycopg") def get_patched_settings(temp_path: Path): diff --git a/tests/no_version/test_db.py b/tests/no_version/test_db.py index 3c0f74acc2..0382b832de 100644 --- a/tests/no_version/test_db.py +++ b/tests/no_version/test_db.py @@ -56,6 +56,7 @@ async def test_sync_db(db_sync, db): DB_ENGINE == "sqlite", reason="Skip if DB is SQLite, pass if it's Postgres" ) def test_DB_ENGINE_is_postgres(): + debug(DB_ENGINE) pass diff --git a/tests/no_version/test_unit_config.py b/tests/no_version/test_unit_config.py index 53a777dfe3..8e1db0572f 100644 --- a/tests/no_version/test_unit_config.py +++ b/tests/no_version/test_unit_config.py @@ -8,7 +8,6 @@ from fractal_server.config import OAuthClientConfig from fractal_server.config import Settings from fractal_server.syringe import Inject -from tests.fixtures_server import DB_ENGINE def test_settings_injection(override_settings): @@ -28,6 +27,7 @@ def test_settings_injection(override_settings): # valid ( dict( + DB_ENGINE="sqlite", JWT_SECRET_KEY="secret", FRACTAL_TASKS_DIR="/tmp", FRACTAL_RUNNER_WORKING_BASE_DIR="/tmp", @@ -38,9 +38,9 @@ def test_settings_injection(override_settings): ), ( dict( + DB_ENGINE="postgres-psycopg", JWT_SECRET_KEY="secret", FRACTAL_TASKS_DIR="/tmp", - DB_ENGINE="postgres-psycopg", POSTGRES_DB="test", FRACTAL_RUNNER_WORKING_BASE_DIR="/tmp", FRACTAL_RUNNER_BACKEND="local", @@ -208,11 +208,6 @@ def test_settings_check( # Create a Settings instance settings = Settings(**settings_dict) - if settings.DB_ENGINE == "postgres-psycopg" and ( - DB_ENGINE != settings.DB_ENGINE - ): - raises = True - # Run Settings.check method if raises: with pytest.raises(FractalConfigurationError):