跳转到主要内容

为Click的Pytest插件

项目描述

Build Coverage Version Python versions License

pytest 插件为 Click.

安装

当前稳定版本

pip install pytest_click

用法

`pytest-click 包含一些可配置的固定值 - cli_runnerisolated_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"

可以通过 runner_setup 标记来配置这两个运行器

import pytest


@pytest.mark.runner_setup(charset="cp1251", env={"test": 1}, echo_stdin=True)
def test_runner_setup(cli_runner):
    ...

所有kwargs都将传递给 click.testing.CliRunner 初始化。

项目详情


下载文件

为您的平台下载文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源分布

pytest_click-1.1.0.tar.gz (5.1 kB 查看哈希值)

上传时间

构建分布

pytest_click-1.1.0-py3-none-any.whl (4.1 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面