pytest

Provide pytest patterns for fixtures, mocking, parametrization, and async tests.

Updated Mar 23, 2026
One-click install
npx skills add https://github.com/giruclawbot/giru-backup --skill pytest-giruclawbot
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/giruclawbot/giru-backup/tree/main/skills/pytest
Command: npx skills add https://github.com/giruclawbot/giru-backup --skill pytest-giruclawbot

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides clear patterns and examples to reduce the friction of writing, organizing, and maintaining Python tests, helping developers produce robust and consistent test suites.

Core Features & Use Cases

  • Test structure & conventions: guidance for organizing test classes, test functions, and naming for discoverability.
  • Fixtures & scopes: examples for reusable fixtures, teardown handling, and scope variations (function, class, module, session).
  • Mocking & isolation: patterns using unittest.mock and MagicMock to isolate dependencies and assert interactions.
  • Parametrization & markers: techniques for parametrized tests, custom markers (slow, integration), skips, and conditional tests.
  • Async & CI: async test patterns, conftest shared fixtures, and recommended pytest CLI flags for CI and local workflows.
  • Use Case: Accelerate building unit and integration tests for a Python service by reusing fixture patterns, mocking external services, and filtering runs with markers.

Quick Start

Request a pytest test suite for a sample user service that includes reusable fixtures, mocking examples, parametrized test cases, marker usage, an async test example, and suggested pytest command-line invocations.

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I write parametrized tests in pytest?

Parametrized tests in pytest use the @pytest.mark.parametrize decorator to run a single test function against multiple input sets, enabling broad coverage with minimal code duplication.

What is the best way to mock external services in Python tests?

Mocking external services in Python tests is best handled using unittest.mock and MagicMock to isolate dependencies, simulate API responses, and assert interaction behaviors without real network calls.

How do pytest fixtures work for setup and teardown?

Pytest fixtures provide reusable setup logic through functions with defined scopes like function, class, module, or session, automatically executing teardown code via yield statements to clean up test environments.

Can I use pytest markers to filter integration tests in CI workflows?

Pytest markers like @pytest.mark.integration or @pytest.mark.slow allow you to categorize tests, enabling CI workflows to selectively run or skip specific test groups using command-line flag filtering.

How do I test async functions with pytest?

Async tests in pytest require async test patterns that execute coroutine functions, allowing you to validate asynchronous Python code behavior using compatible fixture setups and execution loops.