Python pytest Fixtures for CLI Integration Tests Prompt
Design pytest fixtures and integration tests that exercise a Python automation CLI end to end with isolated temp filesystems, fake env, and captured output
- Target user
- engineers who automate ops with Bash and Python
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior automation engineer who writes the tests that let teammates refactor an ops CLI without fear of breaking production behavior. I will provide: - The CLI's entry point and a few representative commands - The side effects it has (writes files, reads env, calls subprocesses or HTTP) - The test runner setup I already have, if any Your job: 1. **Design the fixtures** — define `conftest.py` fixtures for an isolated `tmp_path` workspace, scrubbed/faked environment variables, and a captured stdout/stderr/exit-code harness. 2. **Isolate side effects** — show how to stub subprocess and network calls (monkeypatch, responses, fake binaries on PATH) so tests are deterministic and offline. 3. **Write the integration tests** — cover the happy path, an invalid-input path, and an idempotent re-run, asserting on exit code, output, and resulting filesystem state. 4. **Parametrize** — use `@pytest.mark.parametrize` to cover argument permutations without duplicating test bodies. 5. **Wire it up** — give the `pytest` invocation, marker config, and a coverage command, plus how this slots into CI. Output as: `conftest.py`, a `test_cli.py`, and a short run/CI section, each in its own fenced block. Default to fully isolated, offline, deterministic tests; never let a test touch real network endpoints, shared paths, or the developer's real environment.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Add Pytest Coverage to an Automation Script Prompt
Wrap an existing Python automation script in a pytest suite that mocks subprocess, network, filesystem, and clock side effects so the logic is tested fast and deterministically without touching real systems.
-
Python Click CliRunner Test Suite Prompt
Design a pytest suite that exercises a Click-based CLI end to end using CliRunner, covering exit codes, stdout/stderr separation, prompts, isolated filesystems, and env-var precedence without touching real systems.
-
Testing Automation Scripts with bats and pytest Prompt
Add real automated tests to Bash and Python scripts using bats-core and pytest — mocking external commands, asserting exit codes and output, and covering the error paths so refactors stop breaking production jobs.
-
Python CSV Data-Quality Validator Prompt
Build a Python CLI that validates and cleans CSV/tabular data against declarative quality rules — types, ranges, required fields, uniqueness, referential checks — and emits a structured report of every violation
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.