skillfed

python-testing-patterns

Learn to build reliable test suites in Python using pytest, fixtures, and mocking strategies. This skill covers unit and integration testing, test organization, async testing, and coverage measurement. Discover patterns for parametrized tests, external dependency mocking, and test-driven development workflows.

Python Testing Patterns teaches pytest-based unit testing with fixtures, mocking, and parametrization for Python projects.

AI-generated summary based on this skill's SKILL.md

23 13 MIT updated by NickCrew

Install

NickCrew/Claude-Cortex/python-testing-patterns · repository language: Python

git clone https://github.com/NickCrew/Claude-Cortex
cp -r Claude-Cortex/skills/python-testing-patterns ~/.claude/skills/python-testing-patterns
npx skillfed install NickCrew/Claude-Cortex/python-testing-patterns

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How to write unit tests in python with python-testing-patterns?

python-testing-patterns teaches you to build reliable unit tests using pytest, Python's leading testing framework. You'll learn to organize tests into logical suites, use assertions effectively, and structure test files for maintainability. The skill covers writing clear test cases that validate your code's behavior, implementing setup and teardown logic, and following testing best practices to catch bugs early in development.

What are pytest fixtures and how do I set them up?

python-testing-patterns explains that pytest fixtures are reusable test components that provide data or resources to your tests. You'll learn to define fixtures in conftest.py files, scope them appropriately (function, class, module, or session), and use dependency injection to pass them into test functions. Fixtures handle setup and teardown automatically, reducing code duplication and making tests more maintainable and readable.

How can I mock external APIs in pytest?

python-testing-patterns covers mocking external dependencies and third-party services to isolate your tests from real API calls. You'll learn to use unittest.mock and pytest plugins to replace external calls with controlled substitutes, verify that your code calls dependencies correctly, and test error scenarios without hitting live services. This ensures tests run fast, reliably, and independently of external system availability.

What's the best approach to test-driven development in Python?

python-testing-patterns teaches test-driven development by showing how to write tests before implementation code. You'll learn to set up test fixtures, define expected behavior through assertions, then write minimal code to pass tests. This workflow catches design issues early, ensures comprehensive coverage, and creates self-documenting code. The skill demonstrates how TDD improves code quality and reduces debugging time.

How do I measure and improve test coverage in Python projects?

python-testing-patterns covers measuring test coverage to identify untested code paths. You'll learn to use coverage tools, interpret coverage reports, and set meaningful coverage targets. The skill shows how to identify gaps in your test suite, prioritize testing high-risk areas, and incrementally improve coverage. Understanding coverage metrics helps you build more robust applications and catch edge cases.

Can python-testing-patterns help with async code and property-based testing?

Yes, python-testing-patterns covers advanced testing patterns including async code testing with pytest-asyncio and property-based testing using Hypothesis. You'll learn to test asynchronous functions, handle concurrent operations in tests, and use property-based approaches to generate test cases automatically. These techniques catch subtle bugs in complex code that traditional unit tests might miss.

SKILL.md

rendered from the published skill — quoted content, verbatim

Python Testing Patterns

Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and property-based testing.

When to Use This Skill

  • Writing unit tests for Python functions and classes
  • Setting up comprehensive test suites and infrastructure
  • Implementing test-driven development (TDD) workflows
  • Creating integration tests for APIs, databases, and services
  • Mocking external dependencies and third-party services
  • Testing async code and concurrent operations
  • Implementing property-based testing with Hypothesis
  • Setting up CI/CD test automation
  • Debugging failing tests and improving test

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 13 files
skills/python-testing-patterns/SKILL.md
skills/python-testing-patterns/references/async-testing.md
skills/python-testing-patterns/references/best-practices.md
skills/python-testing-patterns/references/coverage.md
skills/python-testing-patterns/references/fixtures.md
skills/python-testing-patterns/references/integration-testing.md
skills/python-testing-patterns/references/mocking.md
skills/python-testing-patterns/references/monkeypatch.md
skills/python-testing-patterns/references/parametrized-tests.md
skills/python-testing-patterns/references/property-based-testing.md
skills/python-testing-patterns/references/pytest-fundamentals.md
skills/python-testing-patterns/references/test-organization.md
skills/python-testing-patterns/validation/rubric.yaml

Related skills

Tags

test-automation quality-assurance continuous-integration code-validation behavior-verification dependency-isolation assertion-framework test-infrastructure