pytest-testing

Convert Python behavior into pytest test cases with fixtures and mocking.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill solves the problem of writing Python tests that are correct, readable, maintainable, and fast, while using the modern pytest ecosystem to handle unit, integration, and async testing without brittle assertions.

Core Features & Use Cases

  • Test behavior over implementation: Focus assertions on outcomes, not internal calls, so refactors don’t break tests unnecessarily.
  • Right test type selection: Choose the lightest test that provides coverage (unit vs integration vs E2E) based on I/O boundaries.
  • Practical mocking and isolation: Mock external boundaries (HTTP, time, filesystem, env vars) and use real infrastructure when appropriate (e.g., testcontainers for DB integration tests).
  • Async testing with anyio: Write async tests that work with anyio’s pytest plugin approach and avoid the pytest-asyncio pitfalls.
  • Coverage-aware configuration: Use pytest configuration and coverage practices that support CI quality gates.
  • Consistent structure and naming: Apply conventions for naming tests, organizing fixtures, and structuring conftest.py so suites stay scalable.

Quick Start

Ask the AI to write pytest tests for the specific Python function or module you’re working on, including async handling and the right mocking boundaries for HTTP, time, and external resources.

Frequently Asked Questions about pytest-testing

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

FAQPage Schema
How do I write pytest tests for async Python functions without using pytest-asyncio?

Use anyio's pytest plugin to write async tests, avoiding common pytest-asyncio pitfalls. This approach ensures reliable async testing by leveraging anyio's structured concurrency model and native pytest integration for deterministic test execution.

What's the best way to mock external HTTP calls and time in Python integration tests?

Mock external HTTP calls and time in Python integration tests using respx for HTTP boundaries and time-machine for time manipulation. This isolates tests from external dependencies, ensuring deterministic behavior without brittle assertions or unpredictable network latency.

How do I structure pytest fixtures and conftest.py for a scalable test suite?

Structure pytest fixtures and conftest.py by applying consistent naming conventions and organizing fixtures hierarchically based on scope. This keeps test suites maintainable and scalable, allowing shared setup logic to be reused efficiently across unit and integration tests.

When should I use testcontainers for database integration tests instead of mocking?

Use testcontainers for database integration tests when you need real infrastructure to validate actual database interactions, and mock external boundaries when testing service logic. This ensures tests remain fast while verifying true database compatibility.

How do I configure pytest-cov coverage thresholds for CI quality gates?

Configure pytest-cov coverage thresholds for CI quality gates by integrating coverage settings directly within pytest configuration. This enforces minimum coverage requirements and generates reports that block merges when code coverage drops below acceptable project standards.

Why do my pytest tests break when I refactor internal implementation details?

Tests break during refactoring because assertions focus on internal implementation calls rather than behavior outcomes. Writing behavior-focused assertions ensures tests validate expected results, allowing code refactoring without unnecessarily breaking the test suite.