Metadata-Version: 2.5
Name: pytest_click
Version: 2.0.0
Summary: Pytest plugin for Click
Project-URL: Changelog, https://github.com/Stranger6667/pytest-click/blob/master/CHANGELOG.md
Project-URL: Bug Tracker, https://github.com/Stranger6667/pytest-click/issues
Project-URL: Funding, https://github.com/sponsors/Stranger6667
Project-URL: Source Code, https://github.com/Stranger6667/pytest-click
Author-email: Dmitry Dygalo <dmitry@dygalo.dev>
Maintainer-email: Dmitry Dygalo <dmitry@dygalo.dev>
License-Expression: MIT
License-File: LICENSE
Keywords: cli,click,pytest,testing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: click>=6.0
Requires-Dist: pytest>=7.0
Provides-Extra: tests
Requires-Dist: coverage[toml]>=7.2; extra == 'tests'
Requires-Dist: pytest>=8; extra == 'tests'
Description-Content-Type: text/markdown

# pytest-click

[![Build](https://github.com/Stranger6667/pytest-click/actions/workflows/build.yml/badge.svg)](https://github.com/Stranger6667/pytest-click/actions/workflows/build.yml)
[![Coverage](https://codecov.io/github/Stranger6667/pytest-click/coverage.svg?branch=master)](https://codecov.io/github/Stranger6667/pytest-click?branch=master)
[![Version](https://img.shields.io/pypi/v/pytest-click.svg)](https://pypi.org/project/pytest-click/)
[![Python versions](https://img.shields.io/pypi/pyversions/pytest-click.svg)](https://pypi.org/project/pytest-click/)
[![License](https://img.shields.io/pypi/l/pytest-click.svg)](https://opensource.org/licenses/MIT)

[pytest](https://github.com/pytest-dev/pytest) plugin for [Click](https://click.palletsprojects.com/).

## Installation

```
pip install pytest-click
```

## Usage

`pytest-click` comes with two fixtures: `cli_runner` and `isolated_cli_runner`.

```python
import click


def test_cli(cli_runner):
    @click.command()
    @click.argument("name")
    def hello(name):
        click.echo(f"Hello {name}!")

    result = cli_runner.invoke(hello, ["Peter"])
    assert result.exit_code == 0
    assert result.output == "Hello Peter!\n"
```

`isolated_cli_runner` runs each test inside `CliRunner.isolated_filesystem()`:

```python
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 with the `runner_setup` mark:

```python
import pytest


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

All kwargs are passed to `click.testing.CliRunner`.
