Skip to main content

Pytest plugin for Click

Project description

Build Coverage Version Python versions License

pytest plugin for Click.


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_cli(cli_runner):
    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.argument("f", type=click.File())
    def cat(f):

    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)

Uploaded Source

Built Distribution

pytest_click-1.1.0-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page