python-testing

Apply pytest strategies for unit, integration, async, and database tests.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Inconsistent, brittle, or missing tests slow development and allow regressions to reach production; this skill provides practical patterns and rules to make Python test suites reliable, maintainable, and fast. It clarifies how to adopt test-driven development, write clear fixtures, mock external dependencies safely, and set coverage targets so teams can merge with confidence.

Core Features & Use Cases

  • TDD workflow: guidance for red → green → refactor cycles and how to structure iterations for one-shot implementation.
  • pytest fundamentals: recommended test organization, markers, selection strategies, and configuration for CI-friendly runs.
  • Fixtures & scopes: patterns for reusable fixtures at function, module, and session scopes with setup/teardown best practices.
  • Parametrization & markers: how to run matrix tests, provide readable test ids, and separate slow/integration tests from unit suites.
  • Mocking & async testing: safe patterns for patching, autospec, async tests, and asserting calls and exceptions without hitting external services.
  • Coverage and CI: target coverage guidance (80%+ and 100% for critical paths), integration with pytest --cov, and enforcing coverage gates in pipelines.
  • Use case: convert a brittle integration suite into a fast, deterministic set of unit and integration tests with parametrized backends and mock isolation for external APIs.

Quick Start

Ask for a failing pytest unit test for a new function add(a, b), implement the minimal function to make it pass, and then propose a safe refactor while preserving all tests.

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 reusable database and API setup?

Pytest fixtures provide reusable setup for database and API tests by defining functions at function, module, or session scopes. Using these scopes ensures deterministic test execution and clean teardown of external dependencies across your suite.

What is the best way to mock external API calls in async pytest tests?

Mocking external API calls in async pytest tests requires safe patching patterns using autospec. This approach asserts calls and exceptions without hitting external services, ensuring your async test suite remains fast and deterministic.

How do I enforce 80% code coverage targets in a pytest CI pipeline?

Enforcing 80% code coverage targets in a pytest CI pipeline involves integrating pytest-cov and configuring coverage gates. You can enforce 100% coverage for critical paths while maintaining an 80% baseline to merge code with confidence.

How does parametrization work for running matrix tests in pytest?

Parametrization in pytest enables running matrix tests by feeding multiple datasets into a single test function. Providing readable test ids separates slow integration tests from fast unit suites, ensuring clear test execution tracking.

Can I use test-driven development for one-shot Python implementation?

Test-driven development supports one-shot Python implementation through structured red, green, and refactor cycles. You write a failing pytest unit test, implement the minimal function to pass, and then propose a safe refactor preserving all tests.

Why does my pytest integration suite run slowly and fail unpredictably?

A pytest integration suite runs slowly and fails unpredictably due to brittle external dependencies and missing test isolation. Converting it using parametrized backends and mock isolation for external APIs creates a fast, deterministic test suite.