Skip to content
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

refactor noxfile by splitting test matrix across two commands #131

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
django-version: ["3.2", "4.2", "5.0", "main"]
env:
NOX_SESSION: "tests(python='${{ matrix.python-version }}', django='${{ matrix.django-version }}')"
steps:
- uses: actions/checkout@v4

Expand All @@ -36,9 +38,20 @@ jobs:
run: |
python -m pip install --upgrade pip nox

- name: Check if test session exists
run: |
if nox -l | grep -q "${{ env.NOX_SESSION }}"; then
echo "Session exists, proceeding with tests"
echo "RUN_TESTS=true" >> $GITHUB_ENV
else
echo "Session does not exist, skipping tests"
echo "RUN_TESTS=false" >> $GITHUB_ENV
fi

- name: Run tests
if: env.RUN_TESTS == 'true'
run: |
python -m nox --session "tests-${{ matrix.python-version }}(django='${{ matrix.django-version }}')"
python -m nox --session "${{ env.NOX_SESSION }}"

tests:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ venv PY_VERSION="3.11.5":
##################

test:
python -m nox --reuse-existing-virtualenvs
python -m nox --reuse-existing-virtualenvs --session "test"

testall:
python -m nox --reuse-existing-virtualenvs --session "tests"

coverage:
python -m nox --reuse-existing-virtualenvs --session "coverage"
Expand Down
41 changes: 28 additions & 13 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,58 @@
PY311 = "3.11"
PY312 = "3.12"
PY_VERSIONS = [PY38, PY39, PY310, PY311, PY312]
PY_DEFAULT = PY38
PY_DEFAULT = PY_VERSIONS[0]
PY_LATEST = PY_VERSIONS[-1]

DJ32 = "3.2"
DJ42 = "4.2"
DJ50 = "5.0"
DJMAIN = "main"
DJMAIN_MIN_PY = PY310
DJ_VERSIONS = [DJ32, DJ42, DJ50, DJMAIN]
DJ_DEFAULT = DJ32
DJ_LTS = [DJ32, DJ42]
DJ_DEFAULT = DJ_LTS[-1]
DJ_LATEST = DJ_VERSIONS[-2]


def version(ver: str) -> tuple[int, ...]:
"""Convert a string version to a tuple of ints, e.g. "3.10" -> (3, 10)"""
return tuple(map(int, ver.split(".")))


def should_skip(python: str, django: str) -> tuple[bool, str | None]:
def should_skip(python: str, django: str) -> bool:
"""Return True if the test should be skipped"""
if django == DJMAIN and version(python) < version(DJMAIN_MIN_PY):
return True, f"Django {DJMAIN} requires Python {DJMAIN_MIN_PY}+"
# Django main requires Python 3.10+
return True

if django == DJ32 and version(python) >= version(PY312):
return True, f"Django {DJ32} requires Python < {PY312}"
# Django 3.2 requires Python < 3.12
return True

if django == DJ50 and version(python) < version(PY310):
return True, f"Django {DJ50} requires Python {PY310}+"
# Django 5.0 requires Python 3.10+
return True

return False, None
return False


@nox.session(python=PY_VERSIONS)
@nox.parametrize("django", DJ_VERSIONS)
def tests(session, django):
skip = should_skip(session.python, django)
if skip[0]:
session.skip(skip[1])
@nox.session
def test(session):
session.notify(f"tests(python='{PY_DEFAULT}', django='{DJ_DEFAULT}')")


@nox.session
@nox.parametrize(
"python,django",
[
(python, django)
for python in PY_VERSIONS
for django in DJ_VERSIONS
if not should_skip(python, django)
],
)
def tests(session, django):
session.install(".[dev,relay]")

if django == DJMAIN:
Expand Down
Loading