pytest

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

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

Core Features & Use Cases

  • Test Structure: Demonstrates basic test writing, including assertions and exception handling.
  • Fixtures: Explains how to use fixtures for setup/teardown and dependency injection, with various scopes.
  • Mocking: Shows how to mock external dependencies using unittest.mock.patch.
  • Parametrization: Illustrates how to run tests with multiple data sets using @pytest.mark.parametrize.
  • Markers: Covers custom markers for test categorization and conditional skipping.
  • Async Tests: Includes examples for testing asynchronous Python code.
  • Commands: Lists common Pytest command-line options for running and filtering tests.

Quick Start

Use the pytest skill to generate a basic test structure for a Python function.

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I structure Python tests using pytest?

To structure Python tests using pytest, you write functions with standard assertions and handle exceptions directly. This approach eliminates boilerplate, allowing you to validate code behavior and expected errors quickly.

How do I use pytest fixtures for setup and teardown?

Pytest fixtures provide setup and teardown mechanisms along with dependency injection. You define fixture functions with specific scopes to initialize states and supply reusable test data across your test suite.

Can I run the same Python test with multiple data sets?

You can run the same Python test with multiple data sets using the @pytest.mark.parametrize decorator. This parametrization feature executes your test function across varied inputs to ensure broad coverage.

How do I mock external dependencies in a pytest test?

To mock external dependencies in a pytest test, you use unittest.mock.patch. This technique replaces real objects with mock instances, isolating your unit tests from databases, APIs, and other external systems.

Does pytest support testing asynchronous Python code?

Pytest supports testing asynchronous Python code by providing specific patterns for async scenarios. This allows you to validate coroutines and asynchronous application behavior within the standard test runner.

How do I skip or categorize tests in pytest?

You skip or categorize tests in pytest using custom markers. Markers enable conditional skipping based on environment conditions and allow selective execution by filtering specific test categories via command-line options.