Skip to content

Unify tests for speed #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 35 commits into
base: dev/remove-codecov
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
82180a5
Unify tests for speed
kingbuzzman May 27, 2025
f33ffd9
.
kingbuzzman May 27, 2025
f6fe9cb
.
kingbuzzman May 27, 2025
81c2e36
Add pytest import skip for xdist in test_fixtures.py to ensure compat…
kingbuzzman May 27, 2025
447de77
.
kingbuzzman May 27, 2025
5c74876
.
kingbuzzman May 27, 2025
17fc9c0
All these tests now run in 68s... damn!
kingbuzzman May 27, 2025
ec939d5
.
kingbuzzman May 27, 2025
bbe8909
Refactor tox commands in tox.ini and update workflow to use the -f fl…
kingbuzzman May 27, 2025
18abc2b
.
kingbuzzman May 27, 2025
9226882
.
kingbuzzman May 27, 2025
99ffdc4
simpler...
kingbuzzman May 27, 2025
7e0c82b
.
kingbuzzman May 27, 2025
94af128
.
kingbuzzman May 27, 2025
2506c02
.
kingbuzzman May 27, 2025
980a1ab
.
kingbuzzman May 27, 2025
8f26903
.
kingbuzzman May 27, 2025
291e541
more...
kingbuzzman May 27, 2025
278eb94
.
kingbuzzman May 27, 2025
d5ca2d0
.
kingbuzzman May 27, 2025
7aeb0a4
.
kingbuzzman May 27, 2025
e1aabb3
.
kingbuzzman May 27, 2025
3768ab8
.
kingbuzzman May 27, 2025
e7201f9
.
kingbuzzman May 27, 2025
c7c0d9f
.
kingbuzzman May 27, 2025
2b040cb
.
kingbuzzman May 27, 2025
c27c622
Merge branch 'dev/remove-codecov' into dev/speed-tests
kingbuzzman Jun 5, 2025
36344ac
Update main.yml
kingbuzzman Jun 5, 2025
2ed43eb
.
kingbuzzman Jun 5, 2025
b5f158d
.
kingbuzzman Jun 5, 2025
84b70ca
.
kingbuzzman Jun 5, 2025
903e05d
.
kingbuzzman Jun 5, 2025
72dc763
.
kingbuzzman Jun 5, 2025
43e1820
.
kingbuzzman Jun 5, 2025
2c12d04
p312 is pretty slow...
kingbuzzman Jun 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 71 additions & 87 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
permissions:
contents: read
security-events: write
env:
TOXENV: ${{ matrix.name }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -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')
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ postgres = [
"psycopg[binary]",
]
mysql = [
"mysqlclient==2.1.0",
"mysqlclient==2.2.7",
]
xdist = [
"pytest-xdist",
Expand Down
3 changes: 3 additions & 0 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
fixtures are tested in test_database.
"""

import os
import socket
from collections.abc import Generator
from contextlib import contextmanager
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
Expand All @@ -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
Expand Down