python-testing

Teach pytest-based testing patterns including TDD, fixtures, parametrization, and mocking.

1|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/yandy-r/claude-plugins --skill python-testing-yandy-r
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/yandy-r/claude-plugins/tree/main/.cursor-plugin/skills/python-testing
Command: npx skills add https://github.com/yandy-r/claude-plugins --skill python-testing-yandy-r

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Python projects often struggle with inconsistent tests, flaky behavior, and onboarding friction. This Skill provides structured guidance for building robust, pytest-based tests that are easy to maintain and extend.

Core Features & Use Cases

  • TDD workflows (RED-GREEN-REFACTOR) with practical examples
  • Fixtures across function/module/session scopes for reliable test data
  • Parametrization and markers to cover multiple inputs and scenarios
  • Mocking and autospec usage with unittest.mock for isolated tests
  • Async testing support with pytest-asyncio and proper teardown
  • Conftest.py organization and scalable test layout for large projects
  • Clear guidance on achieving target code coverage and meaningful reports

Quick Start

Write a concise pytest-based test suite scaffold for a Python module that demonstrates fixtures, parameterization, and mocks.

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I structure pytest fixtures for module and session scopes in a large project?

Pytest fixtures can be scoped to function, module, or session levels to manage test data lifecycle reliably. Organizing shared fixtures in conftest.py files enables scalable test layout and ensures reusable, isolated test data across large projects.

What's the best way to write async tests with pytest-asyncio?

Async tests with pytest-asyncio execute asynchronous coroutines natively within pytest, ensuring proper teardown after completion. Using the marker on test functions manages the event loop lifecycle, validating asyncio code behavior while maintaining standard assertion mechanics.

How does parametrization work in pytest to cover multiple test scenarios?

Parametrization in pytest allows running a single test function against multiple inputs by defining variable sets and expected outcomes. This approach eliminates redundant test code, systematically covers diverse scenarios, and simplifies maintaining comprehensive test coverage.

How do I use unittest.mock autospec for isolated Python tests?

Autospec with unittest.mock validates mock objects against the real object's specification, preventing silent failures from missing attributes. This approach isolates the system under test by replacing dependencies with type-safe mocks that enforce correct API usage during test execution.

How do I implement a TDD RED-GREEN-REFACTOR workflow in Python?

The TDD workflow starts by writing a failing test (RED), implementing minimal code to pass it (GREEN), and then refactoring the codebase cleanly (REFACTOR). This iterative cycle ensures test coverage drives design decisions, producing maintainable Python modules.

Can I use pytest markers to organize unit, integration, and end-to-end tests?

Pytest markers categorize tests across unit, integration, and end-to-end scenarios to selectively run specific test suites. Markers combined with conftest.py organization provide a scalable test layout, allowing targeted execution and efficient test management for complex applications.