From f8dad4c72321db5fceb61ce8a4f5df30ec88f88d Mon Sep 17 00:00:00 2001 From: Junya Morioka Date: Tue, 8 Sep 2026 08:05:17 +0900 Subject: [PATCH] feat: run pytest in parallel with pytest-xdist by default - Add pytest-xdist to the dev group and regenerate uv.lock - Pass --numprocesses=auto through [tool.pytest] addopts so every pytest invocation, local or CI, distributes tests across all CPU cores --- template/pyproject.toml | 11 +++++++++-- template/uv.lock | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/template/pyproject.toml b/template/pyproject.toml index 686d902..9c7632b 100644 --- a/template/pyproject.toml +++ b/template/pyproject.toml @@ -22,7 +22,14 @@ build-backend = "hatchling.build" packages = ["src/{{package_name}}"] [dependency-groups] -dev = ["prek>=0.5.2", "pytest>=9.1.1", "pytest-cov>=7.1.0", "ruff>=0.16.6", "ty>=0.0.78"] +dev = [ + "prek>=0.5.2", + "pytest>=9.1.1", + "pytest-cov>=7.1.0", + "pytest-xdist>=3.8.0", + "ruff>=0.16.6", + "ty>=0.0.78", +] [tool.ruff] line-length = 100 @@ -82,7 +89,7 @@ convention = "google" [tool.pytest] testpaths = ["tests"] -addopts = ["-ra", "--strict-markers", "--strict-config"] +addopts = ["-ra", "--strict-markers", "--strict-config", "--numprocesses=auto"] xfail_strict = true [tool.coverage.run] diff --git a/template/uv.lock b/template/uv.lock index 5d2d46d..216da90 100644 --- a/template/uv.lock +++ b/template/uv.lock @@ -154,6 +154,7 @@ dev = [ { name = "prek" }, { name = "pytest" }, { name = "pytest-cov" }, + { name = "pytest-xdist" }, { name = "ruff" }, { name = "ty" }, ] @@ -165,6 +166,7 @@ dev = [ { name = "prek", specifier = ">=0.5.2" }, { name = "pytest", specifier = ">=9.1.1" }, { name = "pytest-cov", specifier = ">=7.1.0" }, + { name = "pytest-xdist", specifier = ">=3.8.0" }, { name = "ruff", specifier = ">=0.16.6" }, { name = "ty", specifier = ">=0.0.78" }, ] @@ -181,6 +183,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/8a/0e/97c33bf5009bdbac74fd2beace167cab3f978feb69cc36f1ef79360d6c4e/exceptiongroup-1.3.1-py3-none-any.whl", hash = "sha256:a7a39a3bd276781e98394987d3a5701d0c4edffb633bb7a5144577f82c773598", size = 16740, upload-time = "2025-11-21T23:01:53.443Z" }, ] +[[package]] +name = "execnet" +version = "2.1.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bf/89/780e11f9588d9e7128a3f87788354c7946a9cbb1401ad38a48c4db9a4f07/execnet-2.1.2.tar.gz", hash = "sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd", size = 166622, upload-time = "2025-11-12T09:56:37.75Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ab/84/02fc1827e8cdded4aa65baef11296a9bbe595c474f0d6d758af082d849fd/execnet-2.1.2-py3-none-any.whl", hash = "sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec", size = 40708, upload-time = "2025-11-12T09:56:36.333Z" }, +] + [[package]] name = "iniconfig" version = "2.3.0" @@ -265,6 +276,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678", size = 22876, upload-time = "2026-03-21T20:11:14.438Z" }, ] +[[package]] +name = "pytest-xdist" +version = "3.8.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "execnet" }, + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/78/b4/439b179d1ff526791eb921115fca8e44e596a13efeda518b9d845a619450/pytest_xdist-3.8.0.tar.gz", hash = "sha256:7e578125ec9bc6050861aa93f2d59f1d8d085595d6551c2c90b6f4fad8d3a9f1", size = 88069, upload-time = "2025-07-01T13:30:59.346Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ca/31/d4e37e9e550c2b92a9cbc2e4d0b7420a27224968580b5a447f420847c975/pytest_xdist-3.8.0-py3-none-any.whl", hash = "sha256:202ca578cfeb7370784a8c33d6d05bc6e13b4f25b5053c30a152269fd10f0b88", size = 46396, upload-time = "2025-07-01T13:30:56.632Z" }, +] + [[package]] name = "ruff" version = "0.16.6"