From c683b4a504146b97a3ade86214976d5510e54d54 Mon Sep 17 00:00:00 2001 From: Kevin Deldycke Date: Fri, 6 Nov 2026 10:33:55 +0400 Subject: [PATCH] Run the `stress` tox env in the nightly Stress jobs --- .github/workflows/nightly.yaml | 6 +++--- docs/contributing.md | 7 +++++++ pyproject.toml | 13 +++++++++++-- tests/test_stream_lifecycle.py | 27 +++++++++++++++++++-------- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index 8b13b8158..055d59d46 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -25,9 +25,9 @@ jobs: - {name: Random 3.10, python: '3.10', tox: random} - {name: Random Windows, python: '3.15', tox: random, os: windows-latest} - {name: Random Mac, python: '3.15', tox: random, os: macos-latest} - - {name: Stress 3.15, python: '3.15', tox: stress-py3.15} - - {name: Stress 3.15t, python: '3.15t', tox: stress-py3.15t} - - {name: Stress Mac 3.15t, python: '3.15t', tox: stress-py3.15t, os: macos-latest} + - {name: Stress 3.15, python: '3.15', tox: stress} + - {name: Stress 3.15t, python: '3.15t', tox: stress} + - {name: Stress Mac 3.15t, python: '3.15t', tox: stress, os: macos-latest} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: diff --git a/docs/contributing.md b/docs/contributing.md index 25a242692..553676959 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -18,6 +18,13 @@ Click includes some extra test environments: $ tox r -e stress ``` +- `tox r -e stress-long` runs the stress tests that take + minutes. + + ```shell-session + $ tox r -e stress-long + ``` + - `tox r -e random` runs tests in parallel in a random order to detect test pollution. diff --git a/pyproject.toml b/pyproject.toml index 9f9461069..459017bda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,8 +87,9 @@ filterwarnings = [ ] markers = [ "stress: high-iteration stress tests for race conditions (deselect with '-m \"not stress\"')", + "stress_long: high-iteration stress tests that take minutes (deselect with '-m \"not stress_long\"')", ] -addopts = "-m 'not stress'" +addopts = "-m 'not stress and not stress_long'" [tool.coverage.run] branch = true @@ -147,7 +148,6 @@ env_list = [ "py3.15", "py3.14", "py3.13", "py3.12", "py3.11", "py3.10", "py3.15t", "pypy3.11", - "stress-py3.15", "stress-py3.15t", "style", "typing", "docs", @@ -184,6 +184,15 @@ commands = [[ {replace = "posargs", default = [], extend = true}, ]] +[tool.tox.env.stress-long] +description = "high-iteration stress tests that take minutes" +commands = [[ + "pytest", "-v", "--tb=short", "-x", "-m", "stress_long", + "--basetemp={env_tmp_dir}", + "--override-ini=addopts=", + {replace = "posargs", default = [], extend = true}, +]] + [tool.tox.env.style] description = "run all pre-commit hooks on all files" dependency_groups = ["pre-commit"] diff --git a/tests/test_stream_lifecycle.py b/tests/test_stream_lifecycle.py index b1c7de2be..ef519561e 100644 --- a/tests/test_stream_lifecycle.py +++ b/tests/test_stream_lifecycle.py @@ -17,7 +17,7 @@ 3. Logging interaction: ``CliRunner`` works with active logging handlers 4. Multi-threaded safety: concurrent threads don't cause I/O-on-closed-file 5. Sequential invocations: multiple ``invoke()`` calls don't corrupt state -6. Stress tests (marked ``stress``): high-iteration reproducers for races +6. Stress tests (``stress``, ``stress_long``): high-iteration reproducers for races How to run locally ------------------ @@ -28,12 +28,18 @@ $ pytest tests/test_stream_lifecycle.py -v -Stress tests only (30k iterations, ~52min): +Short stress tests only (20k iterations, ~11s): .. code-block:: shell-session $ pytest tests/test_stream_lifecycle.py -m stress -x --override-ini="addopts=" +Long stress tests only (10k iterations, ~11min): + +.. code-block:: shell-session + + $ pytest tests/test_stream_lifecycle.py -m stress_long -x --override-ini="addopts=" + Everything: .. code-block:: shell-session @@ -491,10 +497,11 @@ def cli(): # --------------------------------------------------------------------------- # Category 6: Stress tests - high-iteration reproducers for race conditions # -# These are marked with ``pytest.mark.stress`` so they can be included or -# excluded independently. The ``tox -e stress`` env collects every -# ``pytest.mark.stress`` test across the suite (not just this file), so -# stress regressions for other components live alongside their unit tests. +# These are marked with ``pytest.mark.stress``, or ``pytest.mark.stress_long`` when they +# take minutes, so they can be included or excluded independently. The ``tox -e stress`` +# and ``tox -e stress-long`` envs collect every test with their marker across the suite +# (not just this file), so stress regressions for other components live alongside their +# unit tests. # --------------------------------------------------------------------------- @@ -534,10 +541,14 @@ def cli(): assert result.exit_code == 0 -@pytest.mark.stress +@pytest.mark.stress_long @pytest.mark.parametrize("_", range(10_000)) def test_stress_gc_between_invocations(_): - """Force GC after each invocation to provoke finalizer races.""" + """Force GC after each invocation to provoke finalizer races. + + Each full collection walks every object of the pytest session, so this test + takes minutes. + """ @click.command() def cli():