Runner
provide.testkit.cli.runner
¶
Enhanced CLI Test Runner.
Provides comprehensive testing support for CLI applications with enhanced output processing, ANSI stripping, and detailed assertions.
Classes¶
CliTestRunner
¶
Enhanced test runner for CLI commands using Click's testing facilities.
Provides additional utilities beyond the basic CliRunner including: - Full output capture (stdout + stderr) - ANSI code stripping - Enhanced error reporting - Isolated filesystem support
Initialize the CLI test runner.
Source code in provide/testkit/cli/runner.py
Functions¶
assert_error
¶
assert_error(
result: Result,
expected_error: str | None = None,
exit_code: int | None = None,
) -> None
Assert that a CLI command failed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Result
|
Click Result object from invoke() |
required |
expected_error
|
str | None
|
Optional error message that should be in the output |
None
|
exit_code
|
int | None
|
Optional specific exit code to check for |
None
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If command succeeded unexpectedly or error details don't match |
Source code in provide/testkit/cli/runner.py
assert_output_contains
¶
Assert that command output contains expected string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Result
|
Click Result object from invoke() |
required |
expected
|
str
|
String that should be in the output |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If expected string not found in output |
Source code in provide/testkit/cli/runner.py
assert_output_not_contains
¶
Assert that command output does not contain unexpected string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Result
|
Click Result object from invoke() |
required |
unexpected
|
str
|
String that should not be in the output |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If unexpected string found in output |
Source code in provide/testkit/cli/runner.py
assert_success
¶
Assert that a CLI command succeeded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Result
|
Click Result object from invoke() |
required |
expected_output
|
str | None
|
Optional string that should be in the output |
None
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If command failed or expected output not found |
Source code in provide/testkit/cli/runner.py
get_full_output
¶
Get combined stdout and stderr with ANSI codes stripped.
This method combines all available output from a CLI command result and removes ANSI escape codes for easier testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Result
|
Click Result object from invoke() |
required |
Returns:
| Type | Description |
|---|---|
str
|
Combined output string with ANSI codes removed |
Source code in provide/testkit/cli/runner.py
invoke
¶
invoke(
cli: Command | Group,
args: list[str] | None = None,
input: str | None = None,
env: dict[str, str] | None = None,
catch_exceptions: bool = True,
**kwargs: Any
) -> Result
Invoke a CLI command for testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cli
|
Command | Group
|
Click command or group to invoke |
required |
args
|
list[str] | None
|
Command line arguments |
None
|
input
|
str | None
|
Input to send to the command |
None
|
env
|
dict[str, str] | None
|
Environment variables |
None
|
catch_exceptions
|
bool
|
Whether to catch exceptions |
True
|
**kwargs
|
Any
|
Additional arguments passed to click.testing.CliRunner.invoke |
{}
|
Returns:
| Type | Description |
|---|---|
Result
|
Click Result object with command output and exit code |
Source code in provide/testkit/cli/runner.py
Functions¶
assert_cli_error
¶
assert_cli_error(
result: Result,
expected_error: str | None = None,
exit_code: int | None = None,
) -> None
Assert that a CLI command failed.