Skip to content

Commit 71eb524

Browse files
authored
tests: run in parallel (#965)
1 parent 64ddef9 commit 71eb524

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ jobs:
6161
- name: Install Nox-under-test (uv)
6262
run: uv pip install --system .
6363
- name: Run tests on ${{ matrix.os }}
64-
run: nox --session "tests-${{ matrix.python-version }}" -- --full-trace
64+
run: nox --session "tests-${{ matrix.python-version }}" -- --durations=10
6565
- name: Run min-version tests on ${{ matrix.os }}
66-
run: nox --session minimums --force-python="${{ matrix.python-version }}" -- --full-trace
66+
run: nox --session minimums --force-python="${{ matrix.python-version }}" -- --durations=10
6767
- name: Run Conda tests
6868
if: matrix.python-version == '3.14'
69-
run: nox --session "conda_tests" -- --full-trace
69+
run: nox --session "conda_tests" -- --durations=5
7070
- name: Save coverage report
7171
uses: actions/upload-artifact@v7
7272
with:

noxfile.py

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
from __future__ import annotations
2323

24-
import contextlib
2524
import functools
2625
import os
2726
import shutil
28-
import sqlite3
2927
import sys
3028

3129
import nox
@@ -43,29 +41,30 @@
4341
def tests(session: nox.Session) -> None:
4442
"""Run test suite with pytest."""
4543

46-
coverage_file = f".coverage.{sys.platform}.{session.python}"
44+
coverage_file = f".coverage.pypi.{sys.platform}.{session.python}"
45+
env = {
46+
"PYTHONWARNDEFAULTENCODING": "1",
47+
"COVERAGE_FILE": coverage_file,
48+
}
49+
parallel = [] if sys.platform.startswith("win32") else ["--numprocesses=auto"]
4750

4851
session.create_tmp() # Fixes permission errors on Windows
4952
session.install(*PYPROJECT["dependency-groups"]["test"], "uv")
5053
session.install("-e.[tox-to-nox,pbs]")
51-
extra_env = {"PYTHONWARNDEFAULTENCODING": "1"}
54+
session.run("coverage", "erase", env=env)
5255
session.run(
56+
"coverage",
57+
"run",
58+
"-m",
5359
"pytest",
54-
"--cov",
55-
"--cov-config",
56-
"pyproject.toml",
57-
"--cov-report=",
60+
*parallel,
61+
"-m",
62+
"not conda",
5863
*session.posargs,
59-
env={
60-
"COVERAGE_FILE": coverage_file,
61-
**extra_env,
62-
},
64+
env=env,
6365
)
64-
65-
if sys.platform.startswith("win"):
66-
with contextlib.closing(sqlite3.connect(coverage_file)) as con, con:
67-
con.execute("UPDATE file SET path = REPLACE(path, '\\', '/')")
68-
con.execute("DELETE FROM file WHERE SUBSTR(path, 2, 1) == ':'")
66+
session.run("coverage", "combine", env=env)
67+
session.run("coverage", "report", env=env)
6968

7069

7170
@nox.session(venv_backend="uv", default=False)
@@ -75,45 +74,54 @@ def minimums(session: nox.Session) -> None:
7574

7675
session.install("-e.", "--group=test", "--resolution=lowest-direct")
7776
session.run("uv", "pip", "list")
78-
session.run("pytest", *session.posargs)
77+
session.run("pytest", "-m", "not conda", *session.posargs)
7978

8079

81-
@nox.session(venv_backend="conda", default=bool(shutil.which("conda")))
82-
def conda_tests(session: nox.Session) -> None:
83-
"""Run test suite set up with conda."""
80+
def xonda_tests(session: nox.Session, xonda: str) -> None:
81+
"""Run test suite set up with conda/mamba/etc."""
82+
83+
coverage_file = f".coverage.{xonda}.{sys.platform}.{session.python}"
84+
env = {"COVERAGE_FILE": coverage_file}
85+
8486
session.conda_install(
8587
"--file", "requirements-conda-test.txt", channel="conda-forge"
8688
)
8789
session.install("-e.", "--no-deps")
8890
# Currently, this doesn't work on Windows either with or without quoting
8991
if not sys.platform.startswith("win32"):
9092
session.conda_install("requests<99")
91-
session.run("pytest", *session.posargs)
93+
94+
session.run("coverage", "erase", env=env)
95+
session.run(
96+
"coverage",
97+
"run",
98+
"-m",
99+
"pytest",
100+
"-m",
101+
"conda",
102+
*session.posargs,
103+
env=env,
104+
)
105+
session.run("coverage", "combine", env=env)
106+
session.run("coverage", "report", env=env)
107+
108+
109+
@nox.session(venv_backend="conda", default=bool(shutil.which("conda")))
110+
def conda_tests(session: nox.Session) -> None:
111+
"""Run test suite set up with conda."""
112+
xonda_tests(session, "conda")
92113

93114

94115
@nox.session(venv_backend="mamba", default=shutil.which("mamba"))
95116
def mamba_tests(session: nox.Session) -> None:
96117
"""Run test suite set up with mamba."""
97-
session.conda_install(
98-
"--file", "requirements-conda-test.txt", channel="conda-forge"
99-
)
100-
session.install("-e.", "--no-deps")
101-
if not sys.platform.startswith("win32"):
102-
session.conda_install("requests<99")
103-
session.run("pytest", *session.posargs)
118+
xonda_tests(session, "mamba")
104119

105120

106121
@nox.session(venv_backend="micromamba", default=shutil.which("micromamba"))
107122
def micromamba_tests(session: nox.Session) -> None:
108123
"""Run test suite set up with micromamba."""
109-
session.conda_install(
110-
"--file", "requirements-conda-test.txt", channel="conda-forge"
111-
)
112-
# Currently, this doesn't work on Windows either with or without quoting
113-
session.install("-e.", "--no-deps")
114-
if not sys.platform.startswith("win32"):
115-
session.conda_install("requests<99")
116-
session.run("pytest", *session.posargs)
124+
xonda_tests(session, "micromamba")
117125

118126

119127
@nox.session(default=False)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test = [
7171
"coverage[toml]>=7.10.3",
7272
"pytest>=7.4; python_version>='3.12'",
7373
"pytest>=7; python_version<'3.12'",
74-
"pytest-cov>=3",
74+
"pytest-xdist>=3",
7575
]
7676
docs = [
7777
"docutils<0.22", # Waiting for sphinx-tabs release

requirements-conda-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ humanize
88
jinja2
99
pbs-installer>=2025.1.6
1010
pytest
11+
pytest-xdist
1112
tox>=4.0.0
1213
virtualenv >=20.14.1
1314
zstandard

0 commit comments

Comments
 (0)