diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0ed900004f54ad77ce3c2cf9a1a327e498f54e83..d03a61bc1b89edc834905face2bce7800557452a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,10 +20,7 @@ run-tox-pipeline: # Change pip's cache directory to be inside the project directory since we can # only cache local items. variables: - POSTGRES_DB: gso-test-db - POSTGRES_USER: nwa - POSTGRES_PASSWORD: nwa - DATABASE_URI_TEST: 'postgresql://nwa:nwa@postgres:5432/gso-test-db' + DATABASE_HOST: 'postgres' PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" cache: diff --git a/requirements.txt b/requirements.txt index 621780cce71a4295884c512ee208c1e5fe9c4323..52ed7721d05e94ead5e862d1b05a56afb9a316d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,4 @@ sphinx-rtd-theme==2.0.0 urllib3_mock==0.3.3 pytest-asyncio==0.23.6 pre-commit~=3.7.0 +pytest-xdist==3.6.1 \ No newline at end of file diff --git a/test/conftest.py b/test/conftest.py index 2eb7e6a28089c621b620fa56d9a55b293c75b099..9366bded878d43e4c16b44a2d31f7735961b6a40 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -142,8 +142,14 @@ def data_config_filename() -> str: @pytest.fixture(scope="session") def db_uri(): - """Provide the database uri configuration to run the migration on.""" - return os.environ.get("DATABASE_URI_TEST", "postgresql://nwa:nwa@localhost/gso-test-db") + """Provide a unique database URI for each pytest-xdist worker, or a default URI if running without xdist.""" + worker_id = os.getenv("PYTEST_XDIST_WORKER") + db_host = os.getenv("DATABASE_HOST", "localhost") + + if worker_id: + return f"postgresql://nwa:nwa@{db_host}/gso-test-db_{worker_id}" + + return f"postgresql://nwa:nwa@{db_host}/gso-test-db" def run_migrations(db_uri: str) -> None: @@ -281,7 +287,7 @@ def partner_factory(): return _create_partner -@pytest.fixture(scope="session") +@pytest.fixture() def geant_partner(partner_factory): return partner_factory(name="GEANT-TEST", email="goat-test@geant.org") diff --git a/tox.ini b/tox.ini index a8eab7b2fc84925ef5a1d2f859e9e5c3bce1eec4..ec9bb3fa4be7a111e700dab259df22b5005d13c2 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ markers = "workflow,noautofixt" filterwarnings = "ignore,default:::gso" [testenv] -passenv = DATABASE_URI_TEST,SKIP_ALL_TESTS,ENVIRONMENT_IGNORE_MUTATION_DISABLED +passenv = DATABASE_HOST,SKIP_ALL_TESTS,ENVIRONMENT_IGNORE_MUTATION_DISABLED setenv = OAUTH2_ACTIVE = False TRANSLATIONS_DIR = ./gso/translations @@ -17,14 +17,7 @@ deps = -r requirements.txt commands = - ruff check --respect-gitignore --preview . - ruff format --respect-gitignore --preview --check . - mypy . - coverage erase - coverage run --source gso --omit="gso/migrations/*" -m pytest {posargs} - coverage xml - coverage html - sh -c "if [ $SKIP_ALL_TESTS -eq 1 ]; then echo 'Skipping coverage report'; else coverage report --fail-under 80; fi" + pytest -n auto {posargs} allowlist_externals = sh