From 85beb0c2ac3cbcb39695172e228d4c4054d41c34 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 2 Jul 2026 12:46:43 +0800 Subject: [PATCH] ci: run tests in parallel with pytest-xdist Add pytest-xdist to the dev group and enable parallel test execution. - Local default: `-n auto --dist worksteal` in pytest.ini, so `pytest` fans out across all cores (worksteal rebalances the heavy Water-sweep and fuzz tests). Full suite ~76s -> ~51s locally. - CI: `-n 2` overrides the auto default. GitHub runners have 4 vCPUs and some tests spawn smoothify's own worker pool, so a smaller fan-out avoids oversubscribing the runner. - README: note the parallel default and `-n 0` to serialise for debugging. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/ci.yml | 7 +++++-- README.md | 8 ++++---- pyproject.toml | 3 ++- pytest.ini | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0c7679..2a455fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,8 +33,11 @@ jobs: run: uv run mypy smoothify/ - name: Test - run: uv run pytest tests/ -x -q + # -n 2 overrides the local `-n auto` default: GitHub runners have 4 + # vCPUs and some tests spawn smoothify's own worker pool, so a smaller + # fan-out avoids oversubscribing the runner. + run: uv run pytest tests/ -n 2 -x -q - name: Notebook smoke test if: matrix.python-version == '3.11' - run: uv run pytest --nbmake examples/*.ipynb -q + run: uv run pytest --nbmake examples/*.ipynb -n 2 -q diff --git a/README.md b/README.md index 86d1ebf..ce5fade 100644 --- a/README.md +++ b/README.md @@ -244,17 +244,17 @@ Smoothify uses [pytest](https://pytest.org/). After cloning the repository, inst # Install dependencies (including the dev group) uv sync -# Run all tests +# Run all tests (parallelised across CPU cores by default via pytest-xdist) uv run pytest tests/ # Run with coverage uv run pytest tests/ --cov=smoothify --cov-report=html -# Run a single test -uv run pytest tests/test_chaikin.py::TestChaikinCornerCutting::test_simple_square_polygon +# Run a single test (add `-n 0` to disable parallelism for clearer output) +uv run pytest tests/test_chaikin.py::TestChaikinCornerCutting::test_simple_square_polygon -n 0 ``` -If you prefer not to use uv, install the dev dependencies into your environment and run `pytest tests/` directly. +The suite runs in parallel by default (`-n auto` in `pytest.ini`); pass `-n 0` to run serially when debugging. If you prefer not to use uv, install the dev dependencies into your environment and run `pytest tests/` directly. ## Contributing diff --git a/pyproject.toml b/pyproject.toml index 0ce6697..fdee1f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ dev = [ "pre-commit>=4.0", "pytest>=8.4.2", "pytest-cov>=6.0.0", + "pytest-xdist>=3.8.0", "ruff>=0.12.2", ] @@ -77,4 +78,4 @@ select = ["E", "F", "B"] [tool.ruff.lint.per-file-ignores] "tests/*" = ["E402"] -"*.ipynb" = ["E402", "E501"] \ No newline at end of file +"*.ipynb" = ["E402", "E501"] diff --git a/pytest.ini b/pytest.ini index 6ce1475..a97ab4d 100644 --- a/pytest.ini +++ b/pytest.ini @@ -9,6 +9,8 @@ addopts = --strict-markers --tb=short --color=yes + -n auto + --dist worksteal markers = slow: marks tests as slow (deselect with '-m "not slow"') integration: marks tests as integration tests