testing/CliRunner: Fix regression related to EOF introduced in 262bdf0 by anlambert · Pull Request #2940 · pallets/click

@anlambert mentioned this pull request

May 22, 2025

kieranyyu

@anlambert

Commit 262bdf0 ensured to raise an EOFError exception on end of input
to simulate tty behavior and avoid blocking prompt during tests when
no more input is available.

However the introduced implementation has a side effect when testing a
click command having a File type option or argument and when it is set
to stdin: the command ends up with error due to the Abort exception
being raised when the stdin EOFError exception is caught.

To prevent this undesirable side effect, prefer to raise the EOFError
exceptions directly from the prompts functions inside the CliRunner
class instead of doing it in the method overriding the iterator protcol
for the _NamedTextIOWrapper class.

Restore previous implementation of a test broken by changes of 262bdf0.

Fixes pallets#2939.

QuLogic added a commit to QuLogic/rasterio that referenced this pull request

Sep 7, 2025

snowman2 pushed a commit to rasterio/rasterio that referenced this pull request

Sep 7, 2025

@Rowlando13

sirosen added a commit to sirosen/pip-tools that referenced this pull request

Sep 19, 2025
The latest `click` release makes two changes which are visible in
`pip-tools`, one of which is only seen in the testsuite.

1.  The default for `Parameter.default` is now an internal `UNSET`
    sentinel.

    Because `UNSET` isn't in the public API, checking `Option.default`
    is not the right way to check if an option has no explicit default
    value. We could use `Option.to_info_dict()`, but we're *also*
    checking for a falsy value right now -- the simple fix is to check
    for a parsed value of `None`.

2.  Changes to EOF handling in `CliRunner.isolation()` result in the
    stream being closed on exit.

    Between pallets/click#2934 and pallets/click#2940, we now get the
    intended behavior for `CliRunner.isolation()`, in that it outputs an
    EOF when the context manager exits. To solve, update a test to read
    stderr before exiting the context manager.

sirosen added a commit to sirosen/pip-tools that referenced this pull request

Sep 19, 2025
The latest `click` release makes two changes which are visible in
`pip-tools`, one of which is only seen in the testsuite.

1.  The default for `Parameter.default` is now an internal `UNSET`
    sentinel.

    Because `UNSET` isn't in the public API, checking `Option.default`
    is not the right way to check if an option has no explicit default
    value. We could use `Option.to_info_dict()`, but we're *also*
    checking for a falsy value right now -- the simple fix is to check
    for a parsed value of `None`.

2.  Changes to EOF handling in `CliRunner.isolation()` result in the
    stream being closed on exit.

    Between pallets/click#2934 and pallets/click#2940, we now get the
    intended behavior for `CliRunner.isolation()`, in that it outputs an
    EOF when the context manager exits. To solve, update a test to read
    stderr before exiting the context manager.

webknjaz

@github-actions github-actions bot locked as resolved and limited conversation to collaborators

Oct 7, 2025