Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Py.test plugin for Click

Project description

Py.test plugin for Click.

Build Coverage Version Python versions License

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.

Files for pytest-click, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size pytest_click-1.0.2-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pytest_click-1.0.2.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page