diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ba3b8db --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,15 @@ +image: python:3.11 + +stages: + - test + +before_script: + - python -V + - python -m venv venv + - ./venv/bin/pip install -e ".[dev]" + + +pytest: + stage: test + script: + - ./venv/bin/pytest \ No newline at end of file diff --git a/argos/server/settings.py b/argos/server/settings.py index 3bdd7b5..3835727 100644 --- a/argos/server/settings.py +++ b/argos/server/settings.py @@ -23,7 +23,9 @@ class DevSettings(Settings): class TestSettings(Settings): - pass + app_env: str = "test" + yaml_file: str = "tests/config.yaml" + database_url: str = "sqlite:////tmp/test-argos.db" class ProdSettings(Settings): diff --git a/pyproject.toml b/pyproject.toml index 0ab9c05..1f58aee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,4 +63,5 @@ testpaths = [ "tests", "argos" ] +fixture_path = "tests/fixtures.py" pythonpath = "." \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 2fa7061..5e3a6a4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,17 +1,16 @@ -from datetime import datetime -from os import environ +import os import pytest from fastapi import FastAPI from sqlalchemy.orm import Session -from argos.server import models - -environ["ARGOS_APP_ENV"] = "test" +os.environ["ARGOS_APP_ENV"] = "test" @pytest.fixture def db() -> Session: + from argos.server import models + app = _create_app() models.Base.metadata.create_all(bind=app.state.engine) yield app.state.SessionLocal() @@ -20,6 +19,8 @@ def db() -> Session: @pytest.fixture def app() -> FastAPI: + from argos.server import models + app = _create_app() models.Base.metadata.create_all(bind=app.state.engine) yield app @@ -33,6 +34,8 @@ def _create_app() -> FastAPI: ) app = get_application() + # Hardcode the database url and the yaml file for testing purpose + # Otherwise, the app will try to read the .env file or the environment variables app.state.settings.database_url = "sqlite:////tmp/test-argos.db" app.state.settings.yaml_file = "tests/config.yaml"