The current stable release:
pip install pytest_click
pytest-click
comes with some configurable fixtures - cli_runner
and isolated_cli_runner
.
import click
def test_fixture(isolated_cli_runner):
@click.command()
@click.argument("f", type=click.File())
def cat(f):
click.echo(f.read())
with open("hello.txt", "w") as f:
f.write("Hello World!")
result = isolated_cli_runner.invoke(cat, ["hello.txt"])
assert result.exit_code == 0
assert result.output == "Hello World!\n"
Both runners can be configured via runner_setup
mark:
All kwargs will be passed to click.testing.CliRunner
initialization.