pytest

Automate Python testing workflows with pytest fixtures, mocking, and markers.

Updated May 29, 2025
One-click install
npx skills add https://github.com/crozzbite/DnDApp --skill pytest-crozzbite
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/crozzbite/DnDApp/tree/main/.agent/skills/pytest
Command: npx skills add https://github.com/crozzbite/DnDApp --skill pytest-crozzbite

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pytest patterns enable concise, reliable Python tests by providing structure for fixtures, mocks, and test organization.

Core Features & Use Cases

  • Fixtures: reusable setup common to many tests
  • Parametrize: run tests with multiple inputs
  • Mocking/patching: isolate units and simulate interactions
  • Markers: selectively run subsets and configure test behavior
  • Async support: test asynchronous code with pytest-asyncio

Quick Start

Run pytest to execute your test suite after writing basic tests using fixtures, mocking, and parametrization.

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 reusable test setup in Python?

Pytest fixtures provide reusable setup logic shared across multiple tests. You define fixtures to initialize common state, then inject them into test functions by passing the fixture name as an argument.

How do I parametrize Python tests to run them with multiple inputs?

Parametrize test functions using the @pytest.mark.parametrize decorator. This applies the test logic to multiple input sets, allowing you to verify behavior across various data combinations within a single test definition.

Can I use pytest to mock and patch dependencies for isolated unit testing?

Yes, pytest supports mocking and patching to isolate units and simulate interactions. You can patch external dependencies to ensure your tests focus strictly on the logic of the specific code block.

How do pytest markers help selectively run a subset of my Python tests?

Pytest markers allow you to tag test functions with custom labels. You can then execute a specific subset of your test suite by filtering based on these markers during the test run command.

Does pytest support testing asynchronous code in Python projects?

Yes, pytest supports testing asynchronous code through pytest-asyncio. This allows you to write and run tests for async functions within your compatible Python environment and project configuration.

What is the best way to organize unit and integration tests in a pytest suite?

Organize unit and integration tests by leveraging pytest fixtures for setup and markers to categorize test types. This streamlines execution and maintains clear separation between isolated logic tests and broader integration tests.