Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ jobs:
with:
python-version: ${{ matrix.python }}
- run: uv run --locked tox run -e ${{ matrix.tox || format('py{0}', matrix.python) }}
stress:
name: stress (${{ matrix.name || matrix.python }})
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
include:
- {python: '3.14'}
- {name: free-threaded, python: '3.14t', tox: stress-py3.14t}
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- uses: astral-sh/setup-uv@5a7eac68fb9809dea845d802897dc5c723910fa3 # v7.1.3
with:
enable-cache: true
prune-cache: false
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: ${{ matrix.python }}
- run: uv run --locked tox run -e ${{ matrix.tox || format('stress-py{0}', matrix.python) }}
typing:
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Unreleased
used without an explicit value. :issue:`3084`
- Hide ``Sentinel.UNSET`` values as ``None`` when using ``lookup_default()``.
:issue:`3136` :pr:`3199` :pr:`3202` :pr:`3209` :pr:`3212` :pr:`3224`
- Prevent ``_NamedTextIOWrapper`` from closing streams owned by ``StreamMixer``.
:issue:`824` :issue:`2991` :issue:`2993` :issue:`3110` :pr:`3139` :pr:`3140`
- Add comprehensive tests for ``CliRunner`` stream lifecycle, covering
logging interaction, multi-threaded safety, and sequential invocation
isolation. Add high-iteration stress tests behind a ``stress`` marker
with a dedicated CI job. :pr:`3139`

Version 8.3.1
--------------
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ testpaths = ["tests"]
filterwarnings = [
"error",
]
markers = [
"stress: high-iteration stress tests for race conditions (deselect with '-m \"not stress\"')",
]
addopts = "-m 'not stress'"

[tool.coverage.run]
branch = true
Expand Down Expand Up @@ -142,6 +146,7 @@ env_list = [
"py3.14", "py3.13", "py3.12", "py3.11", "py3.10",
"py3.14t",
"pypy3.11",
"stress-py3.14", "stress-py3.14t",
"style",
"typing",
"docs",
Expand All @@ -160,6 +165,16 @@ commands = [[
{replace = "posargs", default = [], extend = true},
]]

[tool.tox.env.stress]
description = "stress tests for stream lifecycle race conditions"
commands = [[
"pytest", "-v", "--tb=short", "-x", "-m", "stress",
"--basetemp={env_tmp_dir}",
"--override-ini=addopts=",
"tests/test_stream_lifecycle.py",
{replace = "posargs", default = [], extend = true},
]]

[tool.tox.env.style]
description = "run all pre-commit hooks on all files"
dependency_groups = ["pre-commit"]
Expand Down
21 changes: 9 additions & 12 deletions src/click/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,6 @@ def __init__(self) -> None:
self.stdout: io.BytesIO = BytesIOCopy(copy_to=self.output)
self.stderr: io.BytesIO = BytesIOCopy(copy_to=self.output)

def __del__(self) -> None:
"""
Guarantee that embedded file-like objects are closed in a
predictable order, protecting against races between
self.output being closed and other streams being flushed on close

.. versionadded:: 8.2.2
"""
self.stderr.close()
self.stdout.close()
self.output.close()


class _NamedTextIOWrapper(io.TextIOWrapper):
def __init__(
Expand All @@ -119,6 +107,15 @@ def __init__(
self._name = name
self._mode = mode

def close(self) -> None:
"""
The buffer this object contains belongs to some other object, so
prevent the default __del__ implementation from closing that buffer.

.. versionadded:: 8.3.2
"""
...

@property
def name(self) -> str:
return self._name
Expand Down
Loading
Loading