Pytest Testing Guidelines

Provides pytest guidelines for naming conventions, mocking patterns, and parametrization in Python projects.

2|1|Updated Nov 27, 2025
One-click install
npx skills add https://github.com/canvas-medical/coding-agents --skill pytest-testing-guidelines
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Pytest Testing Guidelines
Source: https://github.com/canvas-medical/coding-agents/tree/main/pytest-forge/skills/pytest-guidelines
Command: npx skills add https://github.com/canvas-medical/coding-agents --skill pytest-testing-guidelines

SYSTEM DOCUMENTATION & REQUIREMENTS

## What problem does it solve? Pytest Testing Guidelines provide a structured framework to write consistent, robust unit tests in Python, emphasizing naming conventions, mock strategies, parametrization, and comprehensive coverage.

## Core Features & Use Cases

  • Standardized test naming conventions and project structure that mirror source files.
  • Clear guidance on mocking with side_effect, mock_calls verification, and avoiding brittle assertions.
  • Practical parametrization patterns and real-world use cases for small utilities up to large codebases.

### Quick Start Begin by reading these guidelines, then apply the templates to your tests:

  • name tests after the corresponding source methods (e.g., test_my_feature)
  • mock external dependencies with patch or patch.object
  • verify mock interactions using a single object-level mock_calls assertion

Frequently Asked Questions about Pytest Testing Guidelines

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

FAQPage Schema
How do I structure pytest unit tests to match my source files?

To structure pytest unit tests effectively, name tests after corresponding source methods like test_my_feature. This standardized naming convention mirrors your source files, ensuring robust and consistent test organization across Python projects.

What is the best way to mock external dependencies in pytest?

The best way to mock external dependencies in pytest is by using patch or patch.object. Enforce the use of side_effect for mocks and verify interactions through a single object-level mock_calls assertion to avoid brittle test assertions.

How do I use parametrization to improve pytest coverage?

You use parametrization to improve pytest coverage by applying practical parametrization patterns across real-world use cases. This approach drives comprehensive 100% coverage by allowing a single test definition to execute multiple input scenarios.

Can I use these pytest guidelines for large codebases?

Yes, you can use these pytest guidelines for large codebases. The framework provides practical parametrization patterns and real-world use cases specifically designed to scale from small utilities up to large Python codebases.

Why should I verify mock_calls at the object level instead of individual assertions?

You should verify mock_calls at the object level to avoid brittle assertions and ensure strict test organization. This method enforces robust mock interaction verification by checking all calls made to a mock object in a single assertion.