pytest

Provide examples and best practices for writing Python tests with Pytest.

Updated Feb 21, 2026
One-click install
npx skills add https://github.com/josemartinrodriguezmortaloni/opencode-config --skill pytest-josemartinrodriguezmortaloni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/josemartinrodriguezmortaloni/opencode-config/tree/main/skill/pytest
Command: npx skills add https://github.com/josemartinrodriguezmortaloni/opencode-config --skill pytest-josemartinrodriguezmortaloni

SYSTEM DOCUMENTATION & REQUIREMENTS

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: Learn basic test organization and assertion patterns.
  • Fixtures: Understand how to create and use fixtures for setup/teardown and dependency injection.
  • Mocking: Master techniques for isolating code under test using unittest.mock.
  • Parametrization: Efficiently test multiple inputs and expected outputs.
  • Markers: Organize and selectively run tests using custom markers.
  • Async Testing: Write tests for asynchronous Python code.
  • Use Case: When developing a new feature in a Python web application, use this Skill to quickly implement unit and integration tests for your new API endpoints, ensuring they behave as expected under various conditions.

Quick Start

Use the pytest skill to write a basic test for a 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 write Python tests using pytest fixtures for setup and teardown?

Python tests using pytest fixtures provide dependency injection and manage setup/teardown logic. You create reusable fixture functions to initialize test states, ensuring robust and maintainable test structures across your codebase.

What is the best way to test multiple inputs in Python using parametrization?

Parametrization in Python testing allows you to run the same test logic against multiple inputs and expected outputs. By applying parametrize markers, you efficiently validate various conditions without duplicating test code.

How do I isolate code under test with mocking in Python?

Mocking in Python isolates the code under test by replacing dependencies with mock objects. Using unittest.mock techniques, you simulate external behaviors to ensure your tests strictly evaluate internal logic.

Can I test asynchronous Python code with pytest?

Yes, you can write tests for asynchronous Python code with pytest. The framework supports async testing scenarios, allowing you to validate coroutines and asynchronous API endpoints effectively under various conditions.

How do I organize and selectively run Python tests using markers?

Markers in Python testing organize and selectively run specific test subsets. By assigning custom markers to test functions, you can filter test execution commands to target only relevant test groups.