Pytest Test Generation: Real, Passing Tests for Python

    by Pavithran

    1

    This skill turns 'write tests for this' into a finished, green test suite.

    $10

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Pytest Test Generation: Real, Passing Tests for Python

    Example session with this skill installed

    Generate tests for my auth.py module. I need 80% coverage and no real network calls.

    • Read your context and instructions
    • Compiled the pytest test generation

    I have analyzed auth.py, detected an existing pytest configuration, and generated a verified test suite. I used unittest.mock to intercept network calls to the identity provider and tmp_path for session token storage.

    Test Suite: test_auth.py

    import pytest
    from unittest.mock import patch
    from auth import Authenticator, UserNotFoundError
    
    @pytest.fixture
    def auth_service():
        return Authenticator(db_path=":memory:")
    
    @pytest.mark.parametrize("username, password, expected_id", [
        ("admin", "correct-pass", 1),
        ("user1", "valid-pass", 2),
    ])
    def test_login_success(auth_service, username, password, expected_id):
        with patch("auth.IdentityServer.verify", return_value=True):
            user_id = auth_service.login(username, password)
            assert user_id == expected_id
            assert auth_service.is_authenticated(user_id) is True
    
    def test_login_invalid_user_raises_error(auth_service):
        with pytest.raises(UserNotFoundError, match="User not found"):
            auth_service.login("nonexistent", "any-pass")
    
    def test_session_creation_writes_to_disk(auth_service, tmp_path):
        auth_service.session_dir = tmp_path
        with patch("auth.IdentityServer.verify", return_value=True):
            uid = auth_service.login("admin", "correct-pass")
            session_file = tmp_path / f"session_{uid}.token"
            assert session_file.exists()
    

    Next steps

    1. Run pytest --cov=auth to confirm the results in your specific environment.
    2. Review the mocked IdentityServer calls to ensure they match your latest API spec.
    3. Add the generated test_auth.py to your tests/ directory.

    Tests: 4 passed, 0 failed
    Coverage: auth.py 88% — missing lines: 42-45 (LDAP fallback logic)
    What I tested: Happy path login, UserNotFoundError branch, and filesystem session persistence.
    What I did NOT test: LDAP fallback as it requires a specialized container environment.
    Files: tests/test_auth.py

    Connects securely to your tools. The creator never sees your data.

    About this skill

    This skill turns 'write tests for this' into a finished, green test suite. It: 1) Detects your test framework — runs a script that reads your project files and tells you whether you're on pytest, unittest, or nothing yet (and what to do in each case). 2) Analyses the target before writing anything — inputs, outputs, every branch, every raise, every boundary value, and every seam where the code touches the outside world (files, network, clock, env vars, randomness). 3) Generates real pytest tests — fixtures for shared setup, parametrize for the happy path, tmp_path for files, mocks for the network, fake clocks for time, and pytest.raises for every error path — with an assertion that a failed operation changed nothing. 4) Runs them and reports coverage gaps — then iterates on exactly the uncovered lines until the suite is green at your coverage target. What makes it different: it teaches the agent how to do the job, step by step, with decision criteria (when to mock vs fake vs use the real thing, how many tests are enough, when to stop) — not a list of best practices. It includes a 7-step process the agent follows in order with a fixed report format, 3 full before/after examples with real pytest output, a fixture-patterns reference, a pre-flight checklist, and a pitfalls guide built from mistakes actually caught while testing. It ships 2 helper scripts (both tested): a framework detector and a coverage-gap reporter. Python + pytest only. It never touches the network or your real files in tests, never reads credentials, and never rewrites your code except for a testability seam you explicitly approve. Verified — real evidence, not claims: tested against 10 target modules: 220 tests, 220 passed, 0 failed, 100% target coverage in all 10 cases, total suite time ~2.5s. Full evidence in TEST-REPORT.md inside the package. Requirements: Python 3.8+ and pytest (pip install pytest pytest-cov; pytest-asyncio for async code). Works inside Claude, ChatGPT, Cursor, Codex, and Gemini CLI.

    Supports Python and pytest only. Requires a local environment where pytest can be installed and executed. Cannot test code without read access.

    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

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 8 days ago

    Software
    Python

    Permissions

    Terminal / Shell
    Network Access
    Read Files
    Write Files
    Environment Variables
    Listed8 days ago

    What's inside

    Frequently Asked Questions

    This skill is designed for any Python project using the pytest framework; it automatically handles dependencies like `pytest-cov` for coverage and `pytest-asyncio` for asynchronous code.

    Unlike generic prompts, this skill performs iterative execution, meaning it runs the tests it writes, identifies failures or import errors, and self-corrects until the suite passes 100% green.

    The skill uses 'seam injection' to automatically identify and mock external dependencies such as API calls, databases, and system clocks, ensuring your tests remain fast and deterministic.

    Yes, the skill is designed to analyze your existing logic and generate additional test cases specifically targeting untested branches and edge cases to help you reach your coverage goals.

    You will receive the full Pytest Test Generation skill, including automated framework detection, logic mapping, and the iterative verification engine, compatible with major AI agent platforms.

    New in Testing & Debugging

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.