Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Py.test plugin for Click

Project Description

Py.test plugin for Click.


The current stable release:

pip install pytest_click


easy_install pytest_click

or from source:

$ sudo python install


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.

Python support

pytest-click supports Python 2.6, 2.7, 3.3, 3.4, 3.5, PyPy, PyPy3 and Jython.

Release History

This version
History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(3.4 kB) Copy SHA256 Hash SHA256
Wheel 2.7 Jan 29, 2016
(8.2 kB) Copy SHA256 Hash SHA256
Source None Jan 29, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting