
Generating Cli Tests
Solid template for writing pytest tests against Typer CLI apps. You get ready-made fixtures for temp storage and sample data, patterns for handling confirmations (the y/n/--force dance), and a breakdown by command type (CRUD operations). The AAA structure examples are clean, and it covers the annoying edge cases like invalid IDs and empty states. Really shines when you're adding test coverage to an existing CLI or want consistent patterns across commands. The CliRunner examples with input strings for confirmations save you from hunting through docs. If you're building task managers, note apps, or any stateful CLI tool, this gets you from zero to decent coverage fast.
- GitHub stars
- 1.3K
- last updated
- Jun 8, 2026
Install
$ npx -y skills add https-deeplearning-ai/sc-agent-skills-files --skill generating-cli-tests --agent claude-codeInstalls into .claude/skills of the current project.
Files
Generating CLI Tests
Patterns for generating tests for Typer CLI commands.
Workflow
- Identify command type (Create/Read/Update/Delete/Bulk)
- Ensure fixtures exist in
conftest.py - Write tests using scenarios below
- Run tests to verify
Fixtures (conftest.py)
import json
import pytest
from typer.testing import CliRunner
@pytest.fixture
def runner():
"""CLI test runner."""
return CliRunner()
@pytest.fixture
def temp_storage(tmp_path, monkeypatch):
"""Empty storage for testing."""
storage_dir = tmp_path / ".task"
storage_dir.mkdir()
storage_file = storage_dir / "tasks.json"
storage_file.write_text(json.dumps({"version": 1, "tasks": []}))
monkeypatch.setenv("TASK_STORAGE_PATH", str(storage_file))
return storage_file
Sponsors
Details
- Repository
- github.com/https-deeplearning-ai/sc-agent-skills-files
- Categories
- Backend & APIs, Testing & QA, AI & Agent Building, Python, CLI & Terminal
- First seen
- Jun 11, 2026