Learn to write Typer CLI tests. Use when asked "how do I test a Typer app?", or when writing tests for Typer commands, prompts, or exit codes.
Date: 2026-03-31
Learn to write effective Typer CLI tests using CliRunner. This skill teaches how to write tests. For evaluating existing tests, see typer-test-quality-skill.
# Basic test invocation
pytest tests/test_cli.py -v
# Run tests matching pattern
pytest -k "test_user" -v
# Run with coverage
pytest --cov=src --cov-report=term-missing
# Run specific test file
pytest tests/test_main.py::test_create_user -v
Typer CLI testing verifies the actual command-line interface works correctly. Unlike unit tests that test individual functions, CLI tests verify:
typer.prompt() is used?The goal is maximum E2E coverage - test the CLI interface, not just the underlying logic.
| Skill | Purpose |
|---|---|
| typer-cli | Build Typer CLI applications (basic patterns) |
| typer-test-quality | Evaluate existing test quality |
| typer-error-handling | Handle errors and exit codes |
| python-test-quality | General Python test quality |
"Test the CLI interface, not the implementation. If you refactor the internals, your tests should still pass."
"Every
runner.invoke()without anexit_codecheck is a silent failure waiting to happen. Be explicit."
"If a command has a prompt, it MUST have a test with
input=. No exceptions. A prompt without a test is untested user input."
"The difference between a test that catches bugs and one that doesn't often comes down to checking the failure case, not just the happy path."
"When writing CLI tests, think from the user's perspective: What could go wrong? What should happen then? Write tests for those scenarios."
"A test that doesn't verify exit codes is like a test that doesn't assert anything - it gives you false confidence."
Note: This skill teaches how to write tests. The existing typer-test-quality-skill evaluates existing tests. Use both together: write tests with this skill, then evaluate them with the quality skill.