Registry / testing / pytest-click

pytest-click

JSON →
library1.1.0pypypi✓ verified 87d ago

PyTest plugin for Click applications. Allows testing Click commands with a simple fixture-based interface. Current version: 1.1.0.

pip install pytest-click
INSTALL
IMPORT
SIG · PYTEST-CLICK
P
pytest-click
testingpythonv1.1.0
Install
2.8s avg
Import
132ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.140s · 31.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.8s · import 0.124s · 32MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CliRunner
from click.testing import CliRunner
from pytest_click import CliRunner
CliRunner is part of click.testing, not pytest-click
click
import click
pytest-click does not re-export click

Minimal test using CliRunner from click.testing.

import click from click.testing import CliRunner @click.command() def hello(): click.echo('Hello, World!') def test_hello(): runner = CliRunner() result = runner.invoke(hello, []) assert result.exit_code == 0 assert 'Hello, World!' in result.output
Debug
Known issues
gotchapytest-click does not export any custom classes. The `CliRunner` class comes from `click.testing`. Common mistake: `from pytest_click import CliRunner` will fail.
fix
Use `from click.testing import CliRunner`.
affects: all
gotchaThe `runner` fixture provided by pytest-click is set up with `mix_stderr=False` by default, which differs from Click's default `mix_stderr=True`. This may cause tests to pass locally but fail in CI if stderr is not handled correctly.
fix
If you rely on stderr mixing, configure the runner fixture manually: `runner = CliRunner(mix_stderr=True)`.
affects: 1.0+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_click'
Trying to import from pytest_click instead of click.testing.
fix
Install pytest-click: pip install pytest-click, then use `from click.testing import CliRunner`.
AttributeError: module 'click' has no attribute 'CliRunner'
Importing `CliRunner` from `click` instead of `click.testing`. Older Click versions might not have `click.testing`; ensure Click is installed.
fix
Install click: pip install click, then use `from click.testing import CliRunner`.
TypeError: invoke() missing 1 required positional argument: 'cli'
Calling `runner.invoke()` without passing the Click command object.
fix
Ensure you pass the command as first argument: `runner.invoke(my_command, ['arg'])`.
Upgrade
Version history
1.1.0latest on PyPI · released Feb 11, 2022
Audit
Dependencies
pytestrequiredPlugin host
Agent activity
6 hits · last 30 days
node
6
Resources