Py.test plugin for Click
Project description
Py.test plugin for Click.
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.1.tar.gz
(3.8 kB
view details)
Built Distribution
File details
Details for the file pytest_click-1.0.1.tar.gz
.
File metadata
- Download URL: pytest_click-1.0.1.tar.gz
- Upload date:
- Size: 3.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa97c6d001440d2e72a2eaa0eb4a804b589dd6afe5916f5b101cecaf6f2bbe4d |
|
MD5 | fbad54597895b0d75f2c22634cbd16fe |
|
BLAKE2b-256 | 96a8f0b7463c6631148d706144c5a3b4db50ce291eef903913942e37c9c4887d |
File details
Details for the file pytest_click-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pytest_click-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d474da6907f22dddd40b03a4f03f0364590e1adea35fd520f68ef022d382f317 |
|
MD5 | 3b81324e442972b30bd64bc261a0984a |
|
BLAKE2b-256 | 6116c8c886ee027ee3fbfe93be312d5e90654ab55864cd2fb820231c5450c6aa |