Pytest plugin for Click
Project description
Installation
The current stable release:
pip install pytest_click
Usage
`pytest-click comes with some configurable fixtures - cli_runner and isolated_cli_runner.
import click
def test_cli(cli_runner):
@click.command()
@click.argument("name")
def hello(name):
click.echo("Hello %s!" % name)
result = cli_runner.invoke(hello, ["Peter"])
assert result.exit_code == 0
assert result.output == "Hello Peter!\n"
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:
import pytest
@pytest.mark.runner_setup(charset="cp1251", env={"test": 1}, echo_stdin=True)
def test_runner_setup(cli_runner):
...
All kwargs will be passed to click.testing.CliRunner initialization.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytest_click-1.1.0.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for pytest_click-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eade4742c2f02c345e78a32534a43e8db04acf98d415090539dacc880b7cd0e9 |
|
MD5 | 68de396f2d033beabffe2732b4b45d20 |
|
BLAKE2b-256 | 721aeb53371999b94b3c995c00117f3a232dbf6f56c7152a52cf3e3777e7d49d |