Skip to content
Snippets Groups Projects
Commit 49d3e1a6 authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

Add pytest-xdist for parallel test execution

parent b32b70b0
No related branches found
No related tags found
1 merge request!292Add pytest-xdist for parallel test execution
Pipeline #89780 passed
__pycache__/
*.egg-info
.coverage
.coverage*
coverage.xml
.vscode
venv
......
......@@ -23,7 +23,7 @@ run-tox-pipeline:
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:
......@@ -36,9 +36,9 @@ run-tox-pipeline:
- pip install virtualenv
- virtualenv venv
- . venv/bin/activate
- pip install tox
script:
- pip install tox
- tox
artifacts:
......
......@@ -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
......@@ -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")
database_host = os.getenv("DATABASE_HOST", "localhost")
if worker_id:
return f"postgresql://nwa:nwa@{database_host}/gso-test-db_{worker_id}"
return os.environ.get("DATABASE_URI_TEST", f"postgresql://nwa:nwa@{database_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")
......
......@@ -6,25 +6,21 @@ markers = "workflow,noautofixt"
filterwarnings = "ignore,default:::gso"
[testenv]
passenv = DATABASE_URI_TEST,SKIP_ALL_TESTS,ENVIRONMENT_IGNORE_MUTATION_DISABLED
passenv = DATABASE_URI_TEST,DATABASE_HOST,SKIP_ALL_TESTS,ENVIRONMENT_IGNORE_MUTATION_DISABLED
setenv =
OAUTH2_ACTIVE = False
TRANSLATIONS_DIR = ./gso/translations
OAUTH2_ACTIVE=False
TRANSLATIONS_DIR=./gso/translations
TESTING=true
EXECUTOR=threadpool
deps =
coverage
pytest-cov
-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"
sh -c 'SKIP_ALL_TESTS=${SKIP_ALL_TESTS:-0}; if [ "$SKIP_ALL_TESTS" = "1" ]; then echo "Skipping coverage report"; else pytest --cov=gso --cov-report=xml --cov-report=html --cov-fail-under=85 -n auto; fi'
allowlist_externals =
sh
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment