- Home
- Skills
- Prompt & Skill Engineering
- pytest companion
Works with the AI Agents you already use
pytest companion
by lyu zhenjun
Expert Python testing agent that generates production-grade pytest suites with mocks, fixtures, and coverage analysis.
$5
/moSubscription · cancel anytime
Secure checkout via Stripe
- Always the latest version
- Delivered live to your agent via MCP
- Cancel anytime, access ends at period end
pytest companion
Example session with this skill installed
Here is my user registration function that calls an external email API and saves to a database. Can you write tests for it?
- Read your context and instructions
- Compiled the pytest companion
I have analyzed the registration logic. It contains three branch points (validation, DB save, email dispatch) and two external dependencies (DB and Email API).
Test Plan
| Function | Scenario | Expected Behavior |
|---|---|---|
register_user | Valid input | Returns user object, DB called, email sent |
register_user | Duplicate email | Raises UserExistsError, email not sent |
register_user | Email API failure | Logs error but returns success (non-blocking) |
register_user | Invalid email format | Raises ValueError, DB not called |
Pytest Suite
import pytest
from unittest.mock import patch, MagicMock
from my_app.auth import register_user, UserExistsError
@pytest.fixture
def mock_db():
with patch("my_app.auth.db_session") as mock: # patch where it's LOOKED UP
yield mock
@pytest.fixture
def mock_email():
with patch("my_app.auth.send_welcome_email") as mock: # patch where it's LOOKED UP
yield mock
@pytest.mark.parametrize("email, password", [
("test@example.com", "pass123"),
("user.name+tag@domain.co", "complex_pass_!"),
])
def test_register_user_valid_input_creates_user(mock_db, mock_email, email, password):
# One logical assertion: successful registration flow
result = register_user(email, password)
assert result.email == email
mock_db.add.assert_called_once()
mock_email.assert_called_once_with(email)
def test_register_user_duplicate_email_raises_error(mock_db, mock_email):
mock_db.add.side_effect = UserExistsError()
with pytest.raises(UserExistsError):
register_user("duplicate@test.com", "password")
mock_email.assert_not_called()
def test_register_user_email_failure_is_non_blocking(mock_db, mock_email):
mock_email.side_effect = Exception("API Down")
result = register_user("user@test.com", "password")
assert result is not None
mock_db.add.assert_called_once()
Next steps
- Run these tests using
pytest --cov=my_app --cov-report=term-missing. - If any lines are marked as missing in the report, paste the output here.
- Review the mock targets in the fixtures to ensure they match your import paths.
Subscription · always the latest version
- Secure checkout via Stripe
- Cancel anytime
- Delivered live via MCP
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.mockormonkeypatchwith correct lookup targets. - Parametrized suites uses
@pytest.mark.parametrizeto handle input/output matrices without code duplication. - Coverage closing parses
term-missingreports to identify specific uncovered lines and writes supplementary tests.
How it works
- Paste your Python code to receive a structural breakdown and a proposed test plan table.
- Review the plan and add custom scenarios or approve the generated list.
- Receive a complete, PEP8-compliant pytest file including all necessary fixtures and mocks.
- 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
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 1 month ago
Permissions
What's inside
Frequently Asked Questions
New in Prompt & Skill Engineering
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Prompt & Skill Engineering.