python-testing-patterns

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

2|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/monang404/lunawave --skill python-testing-patterns-monang404
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing-patterns
Source: https://github.com/monang404/lunawave/tree/main/.agent/skills/python-testing-patterns
Command: npx skills add https://github.com/monang404/lunawave --skill python-testing-patterns-monang404

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Writing reliable Python tests requires knowing pytest fixtures, mocking strategies, async testing, and coverage configuration, which developers often implement inconsistently or skip entirely. ## Core Features & Use Cases - Pytest Patterns: Provides ready-to-use patterns for fixtures, parameterized tests, exception testing, and monkeypatching environment variables. - Mocking & Async Testing: Demonstrates unittest.mock usage for API clients and pytest-asyncio patterns for concurrent code. - Coverage & CI Integration: Includes pytest-cov configuration, test markers, and GitHub Actions workflow templates. - Use Case: When building a new API client, apply the mocking patterns to test HTTP calls without network access, then add parameterized tests to cover edge cases and wire coverage reporting into CI. ## Quick Start Ask the AI to write pytest tests for your Python module using fixtures, mocking, and parameterized cases following these testing 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 unit tests with pytest in Python?▼

Write test functions prefixed with test_ and use plain assert statements to verify behavior. Follow the Arrange-Act-Assert pattern: set up test data, execute the code under test, then verify the results.

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. Configure json.return_value and raise_for_status to mimic success or error responses without network calls.

What is the difference between pytest fixtures and setup methods?▼

Pytest fixtures are declared with the @pytest.fixture decorator and injected into tests as parameters, supporting scopes like function, module, and session. They provide cleaner dependency injection and teardown via yield compared to xUnit-style setup methods.

Does pytest support testing async functions?▼

Yes, pytest supports async tests through the pytest-asyncio plugin. Mark async test functions with @pytest.mark.asyncio and use await inside the test; async fixtures are also supported for setup of asynchronous 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 or --cov-fail-under=80 to enforce a minimum coverage threshold in CI.

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.