Skip to content

Commit

Permalink
Merge pull request #1968 from fractal-analytics-platform/1967-use-db_…
Browse files Browse the repository at this point in the history
…engine-variable-to-determine-how-to-run-tests-rather-than-modulenotfounderror

Use `DB_ENGINE` variable to determine how to run tests, rather than `ModuleNotFoundError`
  • Loading branch information
tcompa authored Oct 25, 2024
2 parents c0e139a + f79aff7 commit 2cc4f94
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 25 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions tests/fixtures_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import random
import sys
from dataclasses import dataclass
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/no_version/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
9 changes: 2 additions & 7 deletions tests/no_version/test_unit_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2cc4f94

Please sign in to comment.