Skip to content

rich_click.testing

Test helpers for CLIs that use Rich for output and prompts.

Classes

NameDescription
CliRunnerA drop-in replacement for click.testing.CliRunner that also isolates Rich.

CliRunnerclass#

class CliRunner(click.testing.CliRunner)

Bases: click.testing.CliRunner

A drop-in replacement for click.testing.CliRunner that also isolates Rich.

While a command runs:

  • Rich prompts (rich.prompt.Prompt, rich.prompt.Confirm, and Console.input()) read from the runner’s input, including password prompts, which would otherwise call getpass.getpass and read from the terminal.
  • Rich’s global console (used by rich.print() and prompts without an explicit console) is reset in place to follow the runner’s color setting, and is not interactive.
  • Environment variables that change Rich output (FORCE_COLOR, NO_COLOR, COLUMNS, …) are unset or pinned, unless given in env.

isolationmethod#

def isolation(input: str | bytes | IO[Any] | None = None, env: Mapping[str, str | None] | None = None, color: bool = False) -> Iterator[Any]