testing/CliRunner: Fix regression related to EOF introduced in 262bdf0#2940
Merged
Rowlando13 merged 2 commits intopallets:mainfrom Sep 13, 2025
Merged
Conversation
kieranyyu
reviewed
May 24, 2025
fddeafc to
ab23822
Compare
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.
ab23822 to
93c6966
Compare
QuLogic
added a commit
to QuLogic/rasterio
that referenced
this pull request
Sep 7, 2025
Due to pallets/click#2939, input from a file is broken. This should be fixed by pallets/click#2940, which is scheduled to be in click 8.3.0.
snowman2
pushed a commit
to rasterio/rasterio
that referenced
this pull request
Sep 7, 2025
Due to pallets/click#2939, input from a file is broken. This should be fixed by pallets/click#2940, which is scheduled to be in click 8.3.0.
Collaborator
|
Sorry @Rowlando13 for the late answer following your review request. But good call for merging this. I could not find a regression with the actual |
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.
4 tasks
webknjaz
reviewed
Sep 22, 2025
| - Lazily import ``shutil``. :pr:`3023` | ||
| - Properly forward exception information to resources registered with | ||
| ``click.core.Context.with_resource()``. :issue:`2447` :pr:`3058` | ||
| - Fix regression related to EOF handling in CliRunner. :issue:`2939`:pr:`2940` |
Contributor
There was a problem hiding this comment.
Lacking whitespace in between two refs ^
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit 262bdf0 ensured to raise an
EOFErrorexception 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
Filetype option or argument and when it is set tostdin: the command ends up with error due to theAbortexception being raised when the stdinEOFErrorexception is caught.To prevent this undesirable side effect, prefer to raise the
EOFErrorexceptions directly from the prompts functions inside theCliRunnerclass instead of doing it in the method overriding the iterator protcol for the_NamedTextIOWrapperclass.Restore previous implementation of a test broken by changes of 262bdf0.
Fixes #2939.