python-cli-testing

Automate Typer/Click CLI testing with CliRunner and pytest fixtures.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/databio/ai-sandbox --skill python-cli-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-cli-testing
Source: https://github.com/databio/ai-sandbox/tree/main/workspaces/.claude/skills/python-cli-testing
Command: npx skills add https://github.com/databio/ai-sandbox --skill python-cli-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Automates and standardizes testing of Typer/Click-based Python CLIs using CliRunner, reducing flaky tests and improving reliability.

Core Features & Use Cases

  • CliRunner-based isolation: Tests execute CLI commands without spawning subprocesses, capturing stdout and stderr.
  • Fixtures and test structure: Provides conftest.py fixtures for reusable test setup.
  • Comprehensive coverage: Tests exit codes, stdout/stderr capture, interactive prompts, and isolated filesystem scenarios.
  • Practical examples: Guides how to structure tests for common Typer/Click patterns and real-world CLI workflows.

Quick Start

Run pytest in your Typer project to start writing CliRunner-based tests for your CLI.

Frequently Asked Questions about python-cli-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Typer and Click CLI commands with pytest?

You test Typer and Click CLI commands with pytest by using CliRunner to execute commands in-process, capturing stdout and stderr while validating exit codes without spawning external subprocesses.

What is the best way to isolate filesystem state during CLI testing?

The best way to isolate filesystem state during CLI testing is using CliRunner's isolated filesystem feature within your pytest fixtures, ensuring test execution remains clean and preventing flaky tests.

How do I handle interactive prompts when testing a Click or Typer application?

You handle interactive prompts when testing a Click or Typer application by passing input strings directly to CliRunner, allowing you to automate prompt responses and validate command workflows reliably.

Do I need conftest.py fixtures to test Typer CLI commands?

You need conftest.py fixtures to test Typer CLI commands effectively, as they provide reusable test setup structures that standardize CliRunner instantiation across your pytest suite.

CliRunner vs subprocess for Python CLI testing: which approach is better?

CliRunner is better than subprocess for Python CLI testing because it executes commands directly in-process without spawning subprocesses, capturing stdout and stderr faster with fewer flaky test scenarios.

Why does my CliRunner test fail to capture stderr in pytest?

CliRunner tests failing to capture stderr in pytest often result from improper output redirection settings; ensure you mix_stderr correctly and invoke commands using the runner to capture both streams accurately.