python-testing-patterns

Implement pytest test suites with fixtures, mocking, parameterization, and coverage reporting.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-testing-patterns-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing-patterns
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/python-testing-patterns
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-testing-patterns-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, pytest-cov, pytest-asyncio, hypothesis, freezegun, requests, sqlalchemy, and includes references (resource) components.

What problem does it solve? Writing reliable Python tests requires knowing pytest fixtures, mocking strategies, parameterization, and async testing patterns, which are easy to get wrong without proven templates. ## Core Features & Use Cases - Pytest Patterns: Provides ready-to-use patterns for fixtures, parameterized tests, exception testing, markers, and test organization following the AAA structure. - Mocking & Isolation: Demonstrates unittest.mock usage, monkeypatching, freezegun time control, and retry-behavior testing to isolate code from external dependencies. - Advanced Coverage: Includes async testing with pytest-asyncio, property-based testing with hypothesis, SQLAlchemy database testing, CI/CD workflow setup, and coverage configuration. - Use Case: When building a new API client, use this Skill to generate a complete test suite with mocked HTTP calls, parameterized input validation tests, and coverage reporting wired into GitHub Actions. ## Quick Start Write pytest tests for my Python module using fixtures, mocking for external API calls, and parameterized cases for edge inputs.

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 unit tests with pytest in Python?

Write test functions prefixed with test_ and use plain assert statements to verify behavior, following the Arrange-Act-Assert pattern. Run tests with the pytest command, which auto-discovers files matching test_*.py.

How to mock API requests 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 the mock was called with expected arguments using assert_called_once_with.

What is the difference between pytest fixture scopes?

Fixture scopes control how often setup runs: function scope creates a fresh instance per test, module scope once per file, and session scope once per test run. Use broader scopes for expensive resources like database connections.

Does pytest support testing async functions?

Yes, pytest supports async tests through the pytest-asyncio plugin using the @pytest.mark.asyncio decorator on async test functions. Async fixtures can also be defined with yield for setup and teardown of async resources.

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 and --cov-fail-under=80 to enforce a minimum coverage threshold.

When should I use property-based testing instead of example-based tests?

Use property-based testing with hypothesis when you want to verify invariants across many generated inputs, such as reversing a string twice returning the original. It complements example-based tests by exploring edge cases you did not anticipate.