Skip to main content

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.

Source Distribution

pytest_click-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

pytest_click-1.0.0-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest_click-1.0.0.tar.gz.

File metadata

  • Download URL: pytest_click-1.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pytest_click-1.0.0.tar.gz
Algorithm Hash digest
SHA256 421155011a9b195acb75fc2f202db9b424ea24768f144f42e5af85519defd345
MD5 16d80193cadf5ce58aed69eebbfd6ca4
BLAKE2b-256 334c824d78dd88fc88656e6a85034f17e006e74ef1a5812d2cc5bc2708eaef05

See more details on using hashes here.

File details

Details for the file pytest_click-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_click-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for pytest_click-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c7705aca7a2c4f0b524ad5e7c700e30a9787ca6ce8d3608449447d14c16e36b8
MD5 474e4301edc8241de2620d9ded4336f0
BLAKE2b-256 457be7b963f6ee73b92f5146c996275f815dc6bada0fb04f4f0f05dc8e90193b

See more details on using hashes here.

Supported by

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