pytest

Guide Python unit test writing with pytest fixtures, parameterization, and mocking.

Updated Mar 9, 2026
One-click install
npx skills add https://github.com/bswrundquist/devtools --skill pytest-bswrundquist
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/bswrundquist/devtools/tree/main/src/devtools/templates/claude/user/.claude/skills/pytest
Command: npx skills add https://github.com/bswrundquist/devtools --skill pytest-bswrundquist

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and best practices for writing effective, maintainable, and robust unit tests in Python using the pytest framework.

Core Features & Use Cases

  • pytest Fundamentals: Covers basic test structure, assertions, and file organization.
  • Advanced Techniques: Demonstrates parameterization, fixtures, mocking, and async testing.
  • Realistic Data: Emphasizes creating fake data over excessive mocking.
  • Use Case: You need to write unit tests for a new Python module. This Skill will guide you on structuring your tests, using fixtures for setup, parameterizing tests for different inputs, and mocking external dependencies.

Quick Start

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

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I write parameterized unit tests in Python?

Parameterized unit tests in Python allow running the same test logic across multiple inputs. The pytest framework enables this by decorating test functions with parameters, reducing code duplication while maintaining comprehensive test coverage.

What is the best way to manage test setup and teardown with pytest fixtures?

Pytest fixtures provide a reliable way to manage test setup and teardown by injecting reusable dependencies into your tests. They initialize required states or data before execution and clean up afterward, ensuring maintainable test suites.

Does pytest support async testing for Python applications?

Yes, pytest supports async testing for Python applications. The framework provides mechanisms to execute asynchronous test functions, allowing developers to properly verify async code patterns and behaviors.

When should I use mocking versus generating fake data in Python unit tests?

When writing Python unit tests, prefer generating realistic fake data over excessive mocking to reflect real-world scenarios. Reserve mocking strictly for isolating external dependencies, ensuring maintainable and robust test suites.

What is the recommended file organization pattern for a Python test suite?

A recommended file organization pattern for a Python test suite involves structuring test files logically alongside application modules. Pytest supports standard directory structures to ensure tests remain discoverable, modular, and maintainable.