pytest

Write Python tests with Pytest fixtures, mocking, parametrization, and markers.

Updated Mar 12, 2026
One-click install
npx skills add https://github.com/fwdarth/agent-teams-lite-domainaware --skill pytest-fwdarth
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/fwdarth/agent-teams-lite-domainaware/tree/main/.opencode/skills/pytest
Command: npx skills add https://github.com/fwdarth/agent-teams-lite-domainaware --skill pytest-fwdarth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and examples for writing effective, maintainable, and robust tests for Python applications using the Pytest framework.

Core Features & Use Cases

  • Test Structure: Demonstrates basic test classes and functions.
  • Fixtures: Explains how to use fixtures for setup/teardown and dependency injection, including different scopes.
  • Mocking: Shows how to mock external dependencies using unittest.mock for isolated testing.
  • Parametrization: Illustrates how to run tests with multiple data sets using @pytest.mark.parametrize.
  • Markers: Covers custom markers for test categorization and skipping.
  • Async Testing: Includes examples for testing asynchronous code.

Quick Start

Use the pytest skill to generate a basic test file for a Python function that adds two numbers.

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I use pytest fixtures for setup and teardown in Python testing?

Pytest fixtures handle setup, teardown, and dependency injection for Python testing. You define fixture functions and inject them into tests by name, controlling their lifecycle through different scopes to manage resources efficiently across test runs.

What is the best way to run a Python test with multiple data sets?

The best way to run a Python test with multiple data sets is parametrization. Using the @pytest.mark.parametrize decorator, you provide variable arguments and expected outcomes to execute the same test logic across different inputs automatically.

How do I mock external dependencies for isolated Python testing?

To mock external dependencies for isolated Python testing, use the unittest.mock library. This allows you to replace real external calls with mock objects, ensuring your tests remain isolated and focus solely on the code under test.

Can I use pytest for testing asynchronous code in Python?

Yes, you can use pytest for testing asynchronous code. The framework provides specific patterns and examples to handle async testing scenarios, allowing you to validate your asynchronous Python functions reliably alongside standard synchronous tests.

How do pytest markers work for categorizing and skipping tests?

Pytest markers allow you to categorize and selectively skip tests. By applying custom markers to test functions, you can filter test execution runs by category or bypass specific tests entirely based on runtime conditions or environment requirements.