python-testing

Implements pytest test suites with fixtures, mocking, parametrization, and coverage reporting.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill python-testing-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/python-testing
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill python-testing-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires knowing pytest patterns for fixtures, mocking, parametrization, async code, and coverage, which developers often implement inconsistently or skip entirely. ## Core Features & Use Cases - TDD Workflow Guidance: Enforces the red-green-refactor cycle with concrete examples for writing failing tests first. - pytest Patterns: Covers fixtures with scopes and teardown, parametrized tests, custom markers, mocking with unittest.mock, and async testing with pytest-asyncio. - Coverage & Configuration: Provides pytest.ini and pyproject.toml setups targeting 80%+ coverage with HTML and terminal reports. - Use Case: When building a FastAPI endpoint, use this Skill to generate a test suite with a test client fixture, mocked database calls, parametrized input validation cases, and a coverage report. ## Quick Start Write pytest tests for my Python module following TDD with fixtures, mocking, and coverage reporting.

Frequently Asked Questions about python-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write pytest fixtures with setup and teardown?▼

Define a function decorated with @pytest.fixture that performs setup, uses yield to provide the resource to the test, and places teardown code after the yield. Fixture scopes like function, module, or session control how often setup runs.

How to mock external API calls in pytest tests?▼

Use unittest.mock.patch as a decorator targeting the import path of the external call, then set return_value or side_effect on the mock. Assert call counts with assert_called_once or assert_awaited_once for async functions.

Does pytest support testing async functions?▼

Yes, pytest-asyncio enables async test support through the @pytest.mark.asyncio decorator. Async fixtures can also be defined with async def and yield to provide resources like async HTTP clients.

How do I run the same pytest test with multiple inputs?▼

Use @pytest.mark.parametrize with a list of input and expected value tuples. The test runs once per parameter set, and you can add ids for readable test names in output.

What code coverage should Python tests target?▼

Target 80%+ overall code coverage with 100% on critical paths. Measure it with pytest --cov=mypackage --cov-report=term-missing to see uncovered lines, and generate HTML reports for detailed inspection.

Why should tests avoid sharing state between each other?▼

Shared state makes tests order-dependent and causes flaky failures that are hard to debug. Each test should be independent, using fixtures to create fresh resources and tmp_path for isolated temporary files.