From 34e0590637a26926164141c1d38bf3bc650c353f Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Wed, 8 May 2024 10:15:17 -0700 Subject: [PATCH 1/2] Update pytest config and requirements to run tests in parallel --- pytest.ini | 2 +- requirements/test-requirements.in | 4 ++++ requirements/test-requirements.txt | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index d280df8b..8a20acb2 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] -addopts = --ds=config.settings.test --reuse-db +addopts = --ds=config.settings.test --reuse-db -n auto python_files = tests.py test_*.py filterwarnings = # Convert all warnings to errors. diff --git a/requirements/test-requirements.in b/requirements/test-requirements.in index f34770c7..0ebeb959 100644 --- a/requirements/test-requirements.in +++ b/requirements/test-requirements.in @@ -5,6 +5,10 @@ types-requests # Pytest pytest # https://github.com/pytest-dev/pytest +# Parallelized tests +pytest-xdist # https://github.com/pytest-dev/pytest-xdist +# Coverage integrated with pytest +pytest-cov # Pytest improvements - progress bar, etc. pytest-sugar # https://github.com/Frozenball/pytest-sugar # Mock HTTP responses diff --git a/requirements/test-requirements.txt b/requirements/test-requirements.txt index 5c5bb7ce..7c016a59 100644 --- a/requirements/test-requirements.txt +++ b/requirements/test-requirements.txt @@ -22,6 +22,8 @@ django-test-migrations==1.3.0 # via -r requirements/test-requirements.in exceptiongroup==1.2.0 # via pytest +execnet==2.1.1 + # via pytest-xdist factory-boy==3.3.0 # via -r requirements/test-requirements.in faker==23.2.1 @@ -44,10 +46,14 @@ pytest==8.2.0 # -r requirements/test-requirements.in # pytest-django # pytest-sugar +pytest-cov==5.0.0 + # via -r requirements/test-requirements.in pytest-django==4.8.0 # via -r requirements/test-requirements.in pytest-sugar==1.0.0 # via -r requirements/test-requirements.in +pytest-xdist==3.6.1 + # via -r requirements/test-requirements.in python-dateutil==2.8.2 # via faker pyyaml==6.0.1 From d974cf4e67325a48d162d3be9abb139fa7e7e14f Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Wed, 8 May 2024 10:15:35 -0700 Subject: [PATCH 2/2] Update CI to run tests in parallel This also required reworking how the coverage reports are generated and uploaded as artifacts. --- .github/workflows/ci.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a7e40a8..677041a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,7 @@ jobs: - python-version: 3.8 # Possible future version. backend: "mariadb" mariadb-version: "10.11" + name: "py${{ matrix.python-version }}-${{ matrix.backend }}-${{ matrix.mariadb-version }}" services: @@ -77,13 +78,18 @@ jobs: run: python manage.py collectstatic --noinput --settings=config.settings.test - name: Run tests - run: coverage run -p -m pytest + run: | + pytest --cov=gregor_django -n auto + mv .coverage .coverage-${{ strategy.job-index }} + + - name: List files for debugging purposes + run: ls -lhta - name: Upload coverage data uses: actions/upload-artifact@v4 with: name: coverage-data-${{ strategy.job-index }} - path: .coverage.* + path: .coverage-${{ strategy.job-index }} coverage: needs: @@ -110,13 +116,14 @@ jobs: - name: Merge coverage files run: | - mv ./artifacts/coverage-data*/.coverage* . + python -m coverage combine ./artifacts/coverage-data*/.coverage-* + python -m coverage xml ls -la .coverage* - - name: Combine coverage data + - name: Report coverage run: | - python -m coverage combine - python -m coverage xml + python -m coverage report + - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: