Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdin click.File has .name attribute when running from CLI, but doesn't when using CliRunner #1064

Closed
nils-werner opened this issue Jul 9, 2018 · 1 comment · Fixed by #1497
Labels
bug f:test runner feature: cli test runner
Milestone

Comments

@nils-werner
Copy link

nils-werner commented Jul 9, 2018

Expected Result

@click.argument('infile', type=click.File('r')) has attribute name in all invokation scenarios

Actual result

@click.argument('infile', type=click.File('r')) doesn't have attribute name when using click.testing.CliRunner.invoke()

Steps to reproduce

@click.command()
@click.argument('infile', type=click.File('r'))
def test(infile):
    print(infile)
    print(infile.name)
test()

run as

python test.py -

returns

<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>
<stdin>

whereas

@click.command()
@click.argument('infile', type=click.File('r'))
def test(infile):
    print(infile)
    print(infile.name)  # Raises AttributeError

from click.testing import CliRunner

runner = CliRunner()
result = runner.invoke(test, ['-'], input="")
print(result.output)
print(result)

returns

<_io.TextIOWrapper encoding='utf-8'>

<Result AttributeError("'_io.BytesIO' object has no attribute 'name'",)>
@ulope

This comment has been minimized.

@jcrotts jcrotts added the bug label May 23, 2019
@davidism davidism added this to the 8.0.0 milestone Aug 14, 2020
@davidism davidism added the f:test runner feature: cli test runner label Aug 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug f:test runner feature: cli test runner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants