diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8a789bc5..68ecd2b0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,8 +26,6 @@ jobs: permissions: contents: read security-events: write - env: - TOXENV: ${{ matrix.name }} steps: - uses: actions/checkout@v4 with: @@ -52,11 +50,13 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install tox==4.26.0 + python -m pip install uv + uv tool install tox==4.26.0 --with tox-uv - name: Run tox - run: tox + run: tox ${TOX_ARGS} + env: + TOX_ARGS: ${{ matrix.use_factor && format('-f {0}', matrix.name) || format('-e {0}', matrix.name) }} - name: Upload zizmor SARIF report into the GitHub repo code scanning if: contains(matrix.name, 'linting') @@ -65,95 +65,81 @@ jobs: sarif_file: zizmor.sarif category: zizmor - - name: Prepare coverage file for upload - if: contains(matrix.name, 'coverage') - run: mv .coverage coverage.${TOXENV} - - name: Upload temporary coverage artifact if: contains(matrix.name, 'coverage') uses: actions/upload-artifact@v4 with: name: coverage-artifact-${{ matrix.name }} - path: coverage.${{ matrix.name }} + path: .coverage.* retention-days: 1 + include-hidden-files: true strategy: fail-fast: false matrix: include: - - name: linting,docs - python: '3.13' - allow_failure: false - - # Explicitly test min pytest. - - name: py313-dj52-sqlite-pytestmin-coverage - python: '3.13' - allow_failure: false - - - name: py313-dj52-postgres-xdist-coverage - python: '3.13' - allow_failure: false - - - name: py313-dj51-postgres-xdist-coverage - python: '3.13' - allow_failure: false - - - name: py312-dj42-postgres-xdist-coverage - python: '3.12' - allow_failure: false - - - name: py311-dj50-postgres-xdist-coverage - python: '3.11' - allow_failure: false - - - name: py311-dj42-postgres-xdist-coverage - python: '3.11' - allow_failure: false - - - name: py310-dj52-postgres-xdist-coverage - python: '3.10' - allow_failure: false - - - name: py310-dj51-postgres-xdist-coverage - python: '3.10' - allow_failure: false - - - name: py310-dj42-postgres-xdist-coverage - python: '3.10' - allow_failure: false - - - name: py311-dj51-mysql-coverage - python: '3.11' - allow_failure: false - - - name: py310-dj42-mysql-coverage - python: '3.10' - allow_failure: false - - - name: py39-dj42-mysql-xdist-coverage - python: '3.9' - allow_failure: false - - - name: py313-djmain-sqlite-coverage - python: '3.13' - allow_failure: true - - - name: py313-dj52-sqlite-coverage - python: '3.13' - allow_failure: true - - - name: py312-dj51-sqlite-xdist-coverage - python: '3.12' - allow_failure: false - - - name: py311-dj42-sqlite-xdist-coverage - python: '3.11' - allow_failure: false - - # pypy3: not included with coverage reports (much slower then). - - name: pypy3-dj42-postgres - python: 'pypy3.9' - allow_failure: false + - name: linting,docs + python: '3.13' + allow_failure: false + use_factor: false + + - name: py39-sqlite-xdist-coverage + python: '3.9' + allow_failure: false + use_factor: true + + - name: py310-sqlite-xdist-coverage + python: '3.10' + allow_failure: false + use_factor: true + + - name: py311-sqlite-xdist-coverage + python: '3.11' + allow_failure: false + use_factor: true + + # start: Speeding up tests by running them in parallel. + - name: py312-dj42-sqlite-xdist-coverage + python: '3.12' + allow_failure: false + use_factor: false + + - name: py312-dj51-sqlite-xdist-coverage + python: '3.12' + allow_failure: false + use_factor: false + + - name: py312-dj52-sqlite-xdist-coverage + python: '3.12' + allow_failure: false + use_factor: false + # end: Speeding up tests by running them in parallel. + + - name: py313-sqlite-xdist-coverage + python: '3.13' + allow_failure: false + use_factor: true + + - name: py313-djmain-postgres-coverage + python: '3.13' + allow_failure: false + use_factor: false + + - name: py313-djmain-mysql-coverage + python: '3.13' + allow_failure: false + use_factor: false + + - name: py313-djmain-sqlite-pytestmin + python: '3.13' + allow_failure: false + use_factor: false + + # pypy3: not included with coverage reports (much slower then). + - name: pypy3-dj52-sqlite + python: 'pypy3.11' + allow_failure: false + use_factor: false report-coverage: name: Report Combined Coverage @@ -178,14 +164,12 @@ jobs: - name: Download all coverage artifacts uses: actions/download-artifact@v4 with: - path: downloaded-coverage-artifacts + path: . pattern: coverage-artifact-* - name: Combine coverage reports run: | - mkdir combined_coverage_data - find downloaded-coverage-artifacts -type f -name 'coverage.*' -exec cp {} combined_coverage_data/ \; - coverage combine combined_coverage_data/* + coverage combine coverage-artifact-* coverage xml coverage html coverage report --show-missing --format=markdown >> $GITHUB_STEP_SUMMARY diff --git a/pyproject.toml b/pyproject.toml index 29acbf43..3a404215 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ postgres = [ "psycopg[binary]", ] mysql = [ - "mysqlclient==2.1.0", + "mysqlclient==2.2.7", ] xdist = [ "pytest-xdist", diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 709ae6c9..4fadcde2 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -4,6 +4,7 @@ fixtures are tested in test_database. """ +import os import socket from collections.abc import Generator from contextlib import contextmanager @@ -443,6 +444,7 @@ def test_set_non_existent(settings): class TestLiveServer: + @pytest.mark.skipif("PYTEST_XDIST_WORKER" in os.environ, reason="xdist in use") def test_settings_before(self) -> None: from django.conf import settings @@ -458,6 +460,7 @@ def test_url(self, live_server) -> None: def test_change_settings(self, live_server, settings) -> None: assert live_server.url == force_str(live_server) + @pytest.mark.skipif("PYTEST_XDIST_WORKER" in os.environ, reason="xdist in use") def test_settings_restored(self) -> None: """Ensure that settings are restored after test_settings_before.""" from django.conf import settings diff --git a/tox.ini b/tox.ini index d6d0e80c..edcb30ab 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,10 @@ [tox] envlist = - py313-dj{main,52,51}-postgres - py312-dj{main,52,51,42}-postgres - py311-dj{main,52,51,42}-postgres - py310-dj{main,52,51,42}-postgres - py39-dj42-postgres + py313-dj{main,52,51}-{sqlite,postgres,mysql}-{xdist}-{coverage} + py312-dj{main,52,51,42}-{sqlite,postgres,mysql}-{xdist}-{coverage} + py{py,}311-dj{52,51,42}-{sqlite,postgres,mysql}-{xdist}-{coverage} + py{py,}310-dj{52,51,42}-{sqlite,postgres,mysql}-{xdist}-{coverage} + py{py,}39-dj42-{sqlite,postgres,mysql}-{xdist}-{coverage} linting [testenv] @@ -16,17 +16,19 @@ dependency_groups = xdist: xdist deps = djmain: https://github.com/django/django/archive/main.tar.gz - dj52: Django>=5.2a1,<6.0 + dj52: Django>=5.2,<6.0 dj51: Django>=5.1,<5.2 dj50: Django>=5.0,<5.1 dj42: Django>=4.2,<4.3 + pytestmin: pytest>=7.0,<7.1 setenv = - mysql: DJANGO_SETTINGS_MODULE=pytest_django_test.settings_mysql + mysql: DJANGO_SETTINGS_MODULE=pytest_django_test.settings_mysql postgres: DJANGO_SETTINGS_MODULE=pytest_django_test.settings_postgres sqlite: DJANGO_SETTINGS_MODULE=pytest_django_test.settings_sqlite sqlite_file: DJANGO_SETTINGS_MODULE=pytest_django_test.settings_sqlite_file + xdist: PYTEST_ADDOPTS=-n auto coverage: PYTESTDJANGO_TEST_RUNNER=coverage run -m pytest coverage: COVERAGE_PROCESS_START={toxinidir}/pyproject.toml @@ -36,9 +38,7 @@ setenv = passenv = PYTEST_ADDOPTS,TERM,TEST_DB_USER,TEST_DB_PASSWORD,TEST_DB_HOST usedevelop = True commands = - coverage: coverage erase {env:PYTESTDJANGO_TEST_RUNNER:pytest} {posargs:tests} - coverage: coverage combine [testenv:linting] dependency_groups = linting