Skip to content

"I/O operation on closed file" error with CliRunner and echo_via_pager under 8.4 #3449

@mschmitzer

Description

@mschmitzer

When echo_via_pager is used in the command, CliRunner.invoke fails with:

ValueError: I/O operation on closed file.

This started happening with Click 8.4, does not happen with 8.3.3.

Reproducer:

from click import command, echo_via_pager
from click.testing import CliRunner

@command()
def cli():
    echo_via_pager("Hello, Click!")

runner = CliRunner()
runner.invoke(cli)

Traceback:

Traceback (most recent call last):
  File ".../echo_via_pager.py", line 11, in <module>
    runner.invoke(cli)
    ~~~~~~~~~~~~~^^^^^
  File ".../.venv/echo-via-pager/lib/python3.13/site-packages/click/testing.py", line 676, in invoke
    sys.stdout.flush()
    ~~~~~~~~~~~~~~~~^^
ValueError: I/O operation on closed file.

Environment:

  • OS: Ubuntu 24.04.4, Linux 6.17
  • Python version: 3.13.5
  • Click version: 8.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions