Skip to content

Commit 9b7ee0f

Browse files
palewireCopilot
andcommitted
Optimize pytest setup
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 56a5020 commit 9b7ee0f

4 files changed

Lines changed: 39 additions & 22 deletions

File tree

Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ UV ?= uv
44
UV_PYTHON ?=
55
PACKAGE ?=
66
COVERAGE_FAIL_UNDER ?= 80
7-
TEST_WORKERS ?= 0
7+
TEST_ARGS ?=
88
RUN = $(if $(UV_PYTHON),UV_PYTHON=$(UV_PYTHON)) $(UV) run
99

10-
.PHONY: all help install install-all install-dev install-test install-docs check verify diff-check lint format-check format fix type-check test test-serial test-parallel coverage build package-check package-verify docs docs-check linkcheck build-docs serve-docs hooks clean
10+
.PHONY: all help install install-all install-dev install-test install-test-extras install-docs check verify diff-check lint format-check format fix type-check test test-serial test-parallel coverage build package-check package-verify docs docs-check linkcheck build-docs serve-docs hooks clean
1111

1212
help: ## Show available commands
1313
@awk 'BEGIN {FS = ":.*## "}; /^[a-zA-Z0-9_-]+:.*## / {printf "%-18s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@@ -23,6 +23,9 @@ install-dev: ## Install dependencies for static checks
2323
install-test: ## Install dependencies for tests
2424
$(UV) sync --group test --locked $(if $(UV_PYTHON),--python $(UV_PYTHON))
2525

26+
install-test-extras: ## Install optional test utilities
27+
$(UV) sync --group test --group test-extras --locked $(if $(UV_PYTHON),--python $(UV_PYTHON))
28+
2629
install-docs: ## Install dependencies for documentation
2730
$(UV) sync --group docs --locked
2831

@@ -51,18 +54,17 @@ fix: ## Apply Ruff lint fixes and formatting
5154
type-check: ## Check static types with ty
5255
$(RUN) ty check
5356

54-
test: ## Run tests
55-
$(RUN) pytest -n $(TEST_WORKERS) -sv
57+
test: ## Run tests serially
58+
$(RUN) pytest $(TEST_ARGS)
5659

57-
test-serial: TEST_WORKERS = 0
5860
test-serial: test ## Run tests without parallel workers
5961

60-
test-parallel: TEST_WORKERS = auto
61-
test-parallel: test ## Run independent tests with parallel workers
62+
test-parallel: ## Run independent tests with parallel workers
63+
$(RUN) pytest -n auto $(TEST_ARGS)
6264

6365
coverage: ## Enforce coverage for PACKAGE
6466
@test -n "$(PACKAGE)" || { echo "Set PACKAGE to the library import name."; exit 2; }
65-
$(RUN) pytest -n $(TEST_WORKERS) --cov="$(PACKAGE)" --cov-branch --cov-report=term-missing:skip-covered --cov-fail-under="$(COVERAGE_FAIL_UNDER)" -sv
67+
$(RUN) pytest $(TEST_ARGS) --cov="$(PACKAGE)" --cov-branch --cov-report=term-missing:skip-covered --cov-fail-under="$(COVERAGE_FAIL_UNDER)"
6668

6769
build: ## Build source and wheel distributions
6870
$(UV) build --sdist --wheel

pyproject.toml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ dev = ["pre-commit", "ruff", "setuptools-scm", "ty", "vulture"]
3636
test = [
3737
"pytest",
3838
"pytest-cov",
39+
"pytest-timeout",
40+
"pytest-xdist",
41+
]
42+
test-extras = [
43+
"freezegun",
44+
"hypothesis",
3945
"pytest-env",
4046
"pytest-ordering",
4147
"pytest-randomly",
4248
"pytest-rerunfailures",
4349
"pytest-runner",
4450
"pytest-sugar",
45-
"pytest-timeout",
4651
"pytest-vcr",
47-
"pytest-xdist",
48-
"freezegun",
49-
"hypothesis",
5052
]
5153
docs = [
5254
"sphinx",
@@ -135,10 +137,16 @@ ignore = [
135137
docstring-code-format = true
136138

137139
[tool.pytest.ini_options]
138-
addopts = ["--strict-config", "--strict-markers", "--durations=10"]
140+
addopts = [
141+
"--strict-config",
142+
"--strict-markers",
143+
"--durations=10",
144+
"--durations-min=1.0",
145+
]
139146
testpaths = ["tests"]
140147
python_files = "test_*.py"
141148
timeout = 60
149+
xfail_strict = true
142150
markers = [
143151
"unit: Unit tests",
144152
"component: Component tests",

tests/test_example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Test the example module."""
22

3+
import pytest
34

4-
def test_example(tmpdir):
5+
6+
@pytest.mark.unit
7+
def test_example():
58
"""Test some simple math."""
69
assert 2 + 2 == 4

uv.lock

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)