Skip to content

Click 8.2.1 CliRunner raises SystemExit(1) when using click.File's stdin support #2939

@olasd

Description

@olasd

In Click 8.2.1, when testing the behavior of a command-line which uses click.File's stdin as an argument, CliRunner.invoke() always throws a SystemExit(1) with Aborted ! on stderr.

Seems like a regression introduced by the change in #2934, as this Aborted! is generated when the main Click endpoint raises an EofError.

Reproducer :

#!/usr/bin/env python3

import click
from click.testing import CliRunner


@click.command()
@click.argument("file_input", type=click.File("r"))
def cli(file_input):
    for line in file_input.readlines():
        print(line.rstrip())


def test_cli():
    result = CliRunner().invoke(cli, ["-"], input="test\n")
    assert result.exit_code == 0, str(result)
    assert result.output == "test\n"


if __name__ == "__main__":
    cli()
nicolasd@pythagore:~/tmp/repro$ uv venv -p python3.13 venv
Using CPython 3.13.3 interpreter at: /usr/bin/python3
Creating virtual environment at: venv
Activate with: source venv/bin/activate
nicolasd@pythagore:~/tmp/repro$ . ./venv/bin/activate
(venv) nicolasd@pythagore:~/tmp/repro$ uv pip install pytest Click==8.2.1
Resolved 5 packages in 5ms
Installed 5 packages in 6ms
 + click==8.2.1
 + iniconfig==2.1.0
 + packaging==25.0
 + pluggy==1.6.0
 + pytest==8.3.5
(venv) nicolasd@pythagore:~/tmp/repro$ echo foo | python3 test_repro.py -
foo
(venv) nicolasd@pythagore:~/tmp/repro$ pytest test_repro.py 
===================================================================== test session starts =====================================================================
platform linux -- Python 3.13.3, pytest-8.3.5, pluggy-1.6.0
rootdir: /home/nicolasd/tmp/repro
collected 1 item                                                                                                                                              

test_repro.py F                                                                                                                                         [100%]

========================================================================== FAILURES ===========================================================================
__________________________________________________________________________ test_cli ___________________________________________________________________________

    def test_cli():
        result = CliRunner().invoke(cli, ["-"], input="test\n")
>       assert result.exit_code == 0, str(result)
E       AssertionError: <Result SystemExit(1)>
E       assert 1 == 0
E        +  where 1 = <Result SystemExit(1)>.exit_code

test_repro.py:16: AssertionError
=================================================================== short test summary info ===================================================================
FAILED test_repro.py::test_cli - AssertionError: <Result SystemExit(1)>
====================================================================== 1 failed in 0.09s ======================================================================
(venv) nicolasd@pythagore:~/tmp/repro$ uv pip install Click==8.2.0
Resolved 1 package in 3ms
Uninstalled 1 package in 1ms
Installed 1 package in 1ms
 - click==8.2.1
 + click==8.2.0
(venv) nicolasd@pythagore:~/tmp/repro$ pytest test_repro.py 
===================================================================== test session starts =====================================================================
platform linux -- Python 3.13.3, pytest-8.3.5, pluggy-1.6.0
rootdir: /home/nicolasd/tmp/repro
collected 1 item                                                                                                                                              

test_repro.py .                                                                                                                                         [100%]

====================================================================== 1 passed in 0.09s ======================================================================

Environment:

  • Python version: 3.13
  • Click version: 8.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions