# pytest companion

> Expert Python testing agent that generates production-grade pytest suites with mocks, fixtures, and coverage analysis.

pytest companion is a subscription AI agent skill on Agensi by lyu zhenjun, in Prompt & Skill Engineering. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5/mo (subscription, cancel anytime)
- Creator: [lyu zhenjun](https://www.agensi.io/creators/lyu-zhenjun)
- Category: [Prompt & Skill Engineering](https://www.agensi.io/skills/prompt-skill-engineering)
- Version: 1.0
- Last updated: 2026-10-15
- Security: scan passed (2026-10-08); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/pytest-companion
- Tags: prompt-engineering, python, testing, pytest, code-quality

## About this skill

Writing unit tests for Python code is a chore that often leads to low coverage or brittle test suites. This skill takes any Python snippet and generates a production-grade pytest suite designed for high coverage and maintainability. It eliminates the friction of mocking external dependencies and writing boilerplate parametrization, ensuring your tests actually catch regressions instead of just checking boxes.

### What it does
- **Structure analysis** identifies functions, branch points, and external dependencies like APIs or databases.
- **Test planning** generates a mandatory table of normal, boundary, and exception scenarios before writing code.
- **Mocking automation** handles all external calls using `unittest.mock` or `monkeypatch` with correct lookup targets.
- **Parametrized suites** uses `@pytest.mark.parametrize` to handle input/output matrices without code duplication.
- **Coverage closing** parses `term-missing` reports to identify specific uncovered lines and writes supplementary tests.

### How it works
1. Paste your Python code to receive a structural breakdown and a proposed test plan table.
2. Review the plan and add custom scenarios or approve the generated list.
3. Receive a complete, PEP8-compliant pytest file including all necessary fixtures and mocks.
4. Paste a coverage report back to the agent to receive targeted tests for any missing branches.

### Frameworks & tools
This skill is purpose-built for Python and the `pytest` ecosystem. It utilizes `pytest-cov` for coverage analysis and the standard `unittest.mock` library for dependency isolation.

### Why this beats prompting it yourself
Generic prompts often produce tests with `assert True` or incorrect mock targets that fail to isolate the code. This skill enforces strict rules: one assertion per test, mandatory boundary testing, and specific comments explaining why a mock target was chosen to prevent common testing pitfalls.

### Use cases
- **Legacy code rescue** by generating comprehensive suites for untested existing modules.
- **TDD workflows** by creating the "Red" step tests before you write implementation logic.
- **CI/CD optimization** by identifying and closing coverage gaps shown in pipeline reports.

### Known limitations
Limited to Python and pytest only. It does not perform integration or E2E testing with real databases or network calls. Large files over 2000 lines require modular processing.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the pytest companion skill from Agensi" and describe your task.
3. Subscribe on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How is this different from just asking a standard AI to 'write tests' for my code?

The skill generates comprehensive, production-grade test suites using pytest-specific features like fixtures and parametrization, whereas generic prompts often produce shallow tests with incorrect mock targets. It enforces a strict test plan and handles complex dependency isolation that standard AI responses typically miss.

### Which programming languages and AI platforms are supported?

This skill is optimized for Python environments using pytest and the standard unittest.mock library. It is compatible with any AI agent or platform that supports Python code analysis and multi-turn text interaction.

### Can the pytest companion handle complex mocking and external API calls?

The agent is designed to identify external dependencies like API calls or database queries and automatically generate the correct mocking logic. It uses specific lookup targets to ensure your tests isolate the unit of code without triggering real network or disk IO.

### I have an existing coverage report; can this skill help me fill in the gaps?

Yes, you can paste your `term-missing` report directly into the agent. It will analyze the specific lines or branches marked as uncovered and generate targeted test cases to help you reach 100% code coverage.

### Are there any limitations on the size or complexity of the Python files I can upload?

While it can handle most Python modules, it is currently limited to files under 2,000 lines to ensure high-quality analysis. For larger applications, we recommend processing your code module-by-module or by individual classes.

### What exactly is included in the purchase of this skill?

You receive the full agent skill configuration and instructions to integrate it into your preferred AI workspace. This includes the logic for structure analysis, test planning, and coverage closing.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
