pytest-click
============
|Build| |Coverage| |Version| |Python versions| |License|
`pytest <https://github.com/pytest-dev/pytest>`_ plugin for `Click <http://click.pocoo.org/>`_.
Installation
------------
The current stable release:
::
pip install pytest_click
Usage
-----
```pytest-click`` comes with some configurable fixtures - ``cli_runner`` and ``isolated_cli_runner``.
.. code:: python
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"
.. code:: 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 via ``runner_setup`` mark:
.. code:: python
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.
.. |Build| image:: https://github.com/Stranger6667/pytest-click/workflows/build/badge.svg
:target: https://github.com/Stranger6667/pytest-click/actions
.. |Coverage| image:: https://codecov.io/github/Stranger6667/pytest-click/coverage.svg?branch=master
:target: https://codecov.io/github/Stranger6667/pytest-click?branch=master
.. |Version| image:: https://img.shields.io/pypi/v/pytest-click.svg
:target: https://pypi.org/project/pytest-click/
.. |Python versions| image:: https://img.shields.io/pypi/pyversions/pytest-click.svg
:target: https://pypi.org/project/pytest-click/
.. |License| image:: https://img.shields.io/pypi/l/pytest-click.svg
:target: https://opensource.org/licenses/MIT
Raw data
{
"_id": null,
"home_page": "https://github.com/Stranger6667/pytest-click",
"name": "pytest-click",
"maintainer": "Dmitry Dygalo",
"docs_url": null,
"requires_python": "",
"maintainer_email": "dadygalo@gmail.com",
"keywords": "",
"author": "Dmitry Dygalo",
"author_email": "dadygalo@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ec/ec/bca3cd29ba2b025ae41666b851f6ff05fb77cb4c13719baaeda6a757772a/pytest_click-1.1.0.tar.gz",
"platform": "",
"description": "pytest-click\n============\n\n|Build| |Coverage| |Version| |Python versions| |License|\n\n`pytest <https://github.com/pytest-dev/pytest>`_ plugin for `Click <http://click.pocoo.org/>`_.\n\nInstallation\n------------\n\nThe current stable release:\n\n::\n\n pip install pytest_click\n\nUsage\n-----\n\n```pytest-click`` comes with some configurable fixtures - ``cli_runner`` and ``isolated_cli_runner``.\n\n.. code:: python\n\n import click\n\n\n def test_cli(cli_runner):\n @click.command()\n @click.argument(\"name\")\n def hello(name):\n click.echo(\"Hello %s!\" % name)\n\n result = cli_runner.invoke(hello, [\"Peter\"])\n assert result.exit_code == 0\n assert result.output == \"Hello Peter!\\n\"\n\n.. code:: python\n\n import click\n\n\n def test_fixture(isolated_cli_runner):\n @click.command()\n @click.argument(\"f\", type=click.File())\n def cat(f):\n click.echo(f.read())\n\n with open(\"hello.txt\", \"w\") as f:\n f.write(\"Hello World!\")\n\n result = isolated_cli_runner.invoke(cat, [\"hello.txt\"])\n assert result.exit_code == 0\n assert result.output == \"Hello World!\\n\"\n\nBoth runners can be configured via ``runner_setup`` mark:\n\n.. code:: python\n\n import pytest\n\n\n @pytest.mark.runner_setup(charset=\"cp1251\", env={\"test\": 1}, echo_stdin=True)\n def test_runner_setup(cli_runner):\n ...\n\nAll kwargs will be passed to ``click.testing.CliRunner`` initialization.\n\n\n.. |Build| image:: https://github.com/Stranger6667/pytest-click/workflows/build/badge.svg\n :target: https://github.com/Stranger6667/pytest-click/actions\n.. |Coverage| image:: https://codecov.io/github/Stranger6667/pytest-click/coverage.svg?branch=master\n :target: https://codecov.io/github/Stranger6667/pytest-click?branch=master\n.. |Version| image:: https://img.shields.io/pypi/v/pytest-click.svg\n :target: https://pypi.org/project/pytest-click/\n.. |Python versions| image:: https://img.shields.io/pypi/pyversions/pytest-click.svg\n :target: https://pypi.org/project/pytest-click/\n.. |License| image:: https://img.shields.io/pypi/l/pytest-click.svg\n :target: https://opensource.org/licenses/MIT\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pytest plugin for Click",
"version": "1.1.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "721aeb53371999b94b3c995c00117f3a232dbf6f56c7152a52cf3e3777e7d49d",
"md5": "68de396f2d033beabffe2732b4b45d20",
"sha256": "eade4742c2f02c345e78a32534a43e8db04acf98d415090539dacc880b7cd0e9"
},
"downloads": -1,
"filename": "pytest_click-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "68de396f2d033beabffe2732b4b45d20",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4110,
"upload_time": "2022-02-11T09:09:33",
"upload_time_iso_8601": "2022-02-11T09:09:33.922120Z",
"url": "https://files.pythonhosted.org/packages/72/1a/eb53371999b94b3c995c00117f3a232dbf6f56c7152a52cf3e3777e7d49d/pytest_click-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ececbca3cd29ba2b025ae41666b851f6ff05fb77cb4c13719baaeda6a757772a",
"md5": "a38c6127bf1ea60615da1c6eca575814",
"sha256": "fdd9f6721f877dda021e7c5dc73e70aecd37e5ed23ec6820f8a7b3fd7b4f8d30"
},
"downloads": -1,
"filename": "pytest_click-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "a38c6127bf1ea60615da1c6eca575814",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5054,
"upload_time": "2022-02-11T09:09:35",
"upload_time_iso_8601": "2022-02-11T09:09:35.169419Z",
"url": "https://files.pythonhosted.org/packages/ec/ec/bca3cd29ba2b025ae41666b851f6ff05fb77cb4c13719baaeda6a757772a/pytest_click-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-02-11 09:09:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Stranger6667",
"github_project": "pytest-click",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "pytest-click"
}