Works with the AI Agents you already use

    pytest companion

    by lyu zhenjun

    1

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

    $5

    /mo

    Subscription · cancel anytime

    Secure checkout via Stripe

    • Always the latest version
    • Delivered live to your agent via MCP
    • Cancel anytime, access ends at period end
    Security scanned
    pytest companion

    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

    FunctionScenarioExpected Behavior
    register_userValid inputReturns user object, DB called, email sent
    register_userDuplicate emailRaises UserExistsError, email not sent
    register_userEmail API failureLogs error but returns success (non-blocking)
    register_userInvalid email formatRaises 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

    1. Run these tests using pytest --cov=my_app --cov-report=term-missing.
    2. If any lines are marked as missing in the report, paste the output here.
    3. Review the mock targets in the fixtures to ensure they match your import paths.
    $5/mo

    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.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

    1. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Network Access
    Listed1 month ago
    Updated1 month ago

    What's inside

    Frequently Asked Questions

    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.

    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.

    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.

    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.

    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.

    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.

    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.