python-testing-patterns

Implements pytest testing strategies including fixtures, mocking, parameterization, and test-driven development.

Updated Feb 8, 2026
One-click install
npx skills add https://github.com/ttnhan18062000/rpg-based-simulation --skill python-testing-patterns-ttnhan18062000
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing-patterns
Source: https://github.com/ttnhan18062000/rpg-based-simulation/tree/main/.agents/skills/python-testing-patterns
Command: npx skills add https://github.com/ttnhan18062000/rpg-based-simulation --skill python-testing-patterns-ttnhan18062000

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, hypothesis, freezegun, pytest-cov, pytest-asyncio.

What problem does it solve? Writing reliable Python tests requires knowing many pytest patterns — fixtures, mocking, parameterization, async testing, and coverage — and this Skill consolidates them into one practical reference so you avoid reinventing test infrastructure. ## Core Features & Use Cases - Fundamental Patterns: Basic pytest tests, fixtures with setup/teardown, parameterized tests, mocking with unittest.mock, and exception testing. - Advanced Patterns: Async test support, monkeypatching, temporary file handling with tmp_path, custom conftest fixtures, and property-based testing with hypothesis. - Repo-Specific Conventions: Scoped pytest runs with registered slow/not-slow markers, CI-aligned test selection, and guidance to use subprocess-launched live servers for API tests. - Use Case: When adding a new feature to a Python service, use this Skill to write isolated unit tests with fixtures, mock external API calls, parameterize edge cases, and configure coverage reporting in CI. ## Quick Start Ask the AI to write pytest tests for a Python module using fixtures, mocking, and parameterized cases following these patterns.

Frequently Asked Questions about python-testing-patterns

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

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

Define a function decorated with @pytest.fixture that performs setup, yields the resource to the test, then runs teardown code after the yield. Use scope parameters like session or module to control how often the fixture is created.

How to mock external API calls in Python tests?

Use unittest.mock's patch to replace requests.get or requests.post with a Mock object whose return_value simulates the HTTP response. Then assert on the mock's call arguments to verify your client made the correct request.

What is the difference between unit tests and integration tests in pytest?

Unit tests verify individual functions or classes in isolation, often with mocked dependencies, while integration tests exercise interactions between components such as APIs and databases. Pytest markers like @pytest.mark.integration let you run each group separately.

Does pytest support testing async functions?

Yes, async test functions are supported by marking them with @pytest.mark.asyncio and awaiting the coroutine under test. Async fixtures can also yield resources with cleanup after the test completes.

Why should I avoid running the full pytest suite during development?

Running the entire suite is slow and includes tests unrelated to your changes. Scope runs to the domain under modification or add -m "not slow" to skip slow-marked tests, matching how CI executes most jobs.

How do I measure test coverage with pytest?

Install pytest-cov and run pytest with --cov=yourpackage to measure coverage. Add --cov-report=term-missing to see uncovered lines or --cov-fail-under=80 to enforce a minimum threshold in CI.