Skip to content

Commit 95af7c6

Browse files
committed
Randomize tests and run them in parallel
Document optional test suites
1 parent 04ef3a6 commit 95af7c6

5 files changed

Lines changed: 129 additions & 1 deletion

File tree

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Released 2026-04-02
1717
with a dedicated CI job. :pr:`3139`
1818
- Fix callable ``flag_value`` being instantiated when used as a default via
1919
``default=True``. :issue:`3121` :pr:`3201` :pr:`3213` :pr:`3225`
20+
- Add optional randomized parallel test execution using ``pytest-randomly`` and
21+
``pytest-xdist`` to detect test pollution and race conditions. :pr:`3151`
22+
- Add contributor documentation for running stress tests, randomized
23+
parallel tests, and Flask smoke tests. :pr:`3151` :pr:`3177`
2024

2125
Version 8.3.1
2226
--------------

docs/contributing.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Contributing to Click
2+
3+
These guidelines are particular to Click and complement the `general ones for all Pallets projects <https://palletsprojects.com/contributing/>`_.
4+
5+
## Running the Test Suite
6+
7+
The default invocation runs the fast unit tests:
8+
9+
```shell-session
10+
$ tox
11+
```
12+
13+
Or without tox:
14+
15+
```shell-session
16+
$ pytest
17+
```
18+
19+
### Stress Tests
20+
21+
These are a collection of long-running tests that reproduce race conditions in `CliRunner`. They are marked with `@pytest.mark.stress`.
22+
23+
Run them with the dedicated tox environment:
24+
25+
```shell-session
26+
$ tox -e stress-py3.14
27+
```
28+
29+
Or directly with pytest:
30+
31+
```shell-session
32+
$ pytest tests/test_stream_lifecycle.py -m stress -x --override-ini="addopts="
33+
```
34+
35+
These tests run 30_000 iterations each and take a long time. Use `-x` to stop at the first failure.
36+
37+
### Randomized & Parallel Tests
38+
39+
Runs the full test suite in random order across multiple processes to detect test pollution and race conditions. This uses `pytest-randomly` and `pytest-xdist`.
40+
41+
```shell-session
42+
$ tox -e random
43+
```
44+
45+
You can reproduce a specific ordering by passing the seed printed at the start of the run:
46+
47+
```shell-session
48+
$ tox -e random -- -p randomly -p no:randomly -p randomly --randomly-seed=12345
49+
```
50+
51+
### Flask Smoke Tests
52+
53+
A CI workflow (`.github/workflows/test-flask.yaml`) runs Flask's own test suite against Click's `main` branch. This catches regressions that would break Flask, Click's primary downstream consumer.
54+
55+
The workflow clones Flask, installs it, then overrides Click with the current branch. To replicate locally:
56+
57+
```shell-session
58+
$ git clone https://github.com/pallets/flask
59+
$ cd flask
60+
$ uv venv --python 3.14
61+
$ uv sync --all-extras
62+
$ uv run --with "git+https://github.com/pallets/click.git@main" -- pytest
63+
```
64+
65+
Replace `@main` with your branch or a local path (`-e /path/to/click`) to test local changes.

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ About Project
133133

134134
* `Version Policy <https://palletsprojects.com/versions>`_
135135

136-
* `Contributing <https://palletsprojects.com/contributing/>`_
136+
* `General Contributing Guidelines <https://palletsprojects.com/contributing/>`_
137137

138138
* `Donate <https://palletsprojects.com/donate>`_
139139

140140
.. toctree::
141141
:maxdepth: 1
142142

143+
contributing
143144
contrib
144145
license
145146
changes

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ pre-commit = [
5151
tests = [
5252
"pytest",
5353
]
54+
tests-random = [
55+
"pytest",
56+
"pytest-randomly",
57+
"pytest-xdist",
58+
]
5459
typing = [
5560
"mypy",
5661
"pyright",
@@ -165,6 +170,15 @@ commands = [[
165170
{replace = "posargs", default = [], extend = true},
166171
]]
167172

173+
[tool.tox.env.random]
174+
description = "randomized parallel tests to detect test pollution and race conditions"
175+
dependency_groups = ["tests-random"]
176+
commands = [[
177+
"pytest", "-v", "--tb=short", "--numprocesses=auto",
178+
"--basetemp={env_tmp_dir}",
179+
{replace = "posargs", default = [], extend = true},
180+
]]
181+
168182
[tool.tox.env.stress]
169183
description = "stress tests for stream lifecycle race conditions"
170184
commands = [[

uv.lock

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

0 commit comments

Comments
 (0)